[英]How to get the activity or application context in AndroidTestCase
I am writing some test case with AndroidTestCase. 我正在用AndroidTestCase编写一些测试用例。 I want call getCacheDir to get the directory. 我想调用getCacheDir来获取目录。
/data/data/com.mypackage/cache
But I have not start up the activity or application. 但是我还没有启动活动或应用程序。 it there any way I can get the activity or application context in AndroidTestCase. 它可以以任何方式在AndroidTestCase中获取活动或应用程序上下文。
您可以在AndroidTestCase的子类中简单地重写getContext()
Since you are extending the AndroidTestCase, you can just use the call getContext() to retrieve the context. 由于您正在扩展AndroidTestCase,因此只需使用调用getContext()即可检索上下文。 AndroidTestCase implements it for you. AndroidTestCase为您实现了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.