有人知道从ServiceTestCase扩展时如何访问JUnit自己的项目res/文件夹编译的R实例吗?
通常的方法不起作用:
getInstrumentation().getContext().getResources()...因为事实证明ServiceTestCase没有getInstrumentation(),因为它没有扩展InstrumentationTestCase方法。
提前谢谢。
发布于 2012-11-16 19:43:57
这个hack来自我的ServiceTestCase子类:
Context context = getContext().createPackageContext(this.getClass().getPackage().getName(),
Context.CONTEXT_IGNORE_SECURITY);
context.getResources()...尽管更标准的方式是受欢迎的。
https://stackoverflow.com/questions/13415582
复制相似问题