有谁知道如何在从ServiceTestCase
扩展时访问JUnit 自己的项目res/
文件夹编译的R
实例? ?
通常的方法行不通:
getInstrumentation().getContext().getResources()...
因为事实证明 ServiceTestCase
没有 getInstrumentation()
因为它没有扩展 InstrumentationTestCase
方法。
提前致谢。
最佳答案
这个 hack 从我的 ServiceTestCase
子类中工作:
Context context = getContext().createPackageContext(this.getClass().getPackage().getName(),
Context.CONTEXT_IGNORE_SECURITY);
context.getResources()...
尽管欢迎使用更标准的方法。
关于android - 使用 ServiceTestCase 访问 JUnit 的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13415582/