从ServiceTestCase
扩展时,是否有人知道如何访问JUnit自己的项目res/
文件夹编译R
实例?
通常的方法不起作用:
getInstrumentation().getContext().getResources()...
因为结果ServiceTestCase
没有getInstrumentation()
,因为它没有扩展InstrumentationTestCase
方法。
提前致谢。
答案 0 :(得分:1)
这个 hack 可以从我的ServiceTestCase
子类中运行:
Context context = getContext().createPackageContext(this.getClass().getPackage().getName(),
Context.CONTEXT_IGNORE_SECURITY);
context.getResources()...
虽然欢迎采用更标准的方法。