开发者

Android unit test/test.runner - access to Application object

开发者 https://www.devze.com 2023-02-20 15:55 出处:网络
I\'m using the android.test.runner library and the AndroidTestCase etc. to create some unit tests. I\'m finding it useful, but one test requires access to the application object. Usually I just get th

I'm using the android.test.runner library and the AndroidTestCase etc. to create some unit tests. I'm finding it useful, but one test requires access to the application object. Usually I just get that from the activity context, e.g.

AppState appState = ((AppState) myActivity.getApplicationContext());

However, the unit tests are in a class which extends AndroidTextCase, and as far as I can see there is no getApplicationContext available. There is a getContext, but I'm not c开发者_StackOverflowlear if that's what I want. What's the best course of action?


Are you testing your AppState object, or trying to test something else which relies on it? If you are not testing AppState in this instance can you use a tool such as Mockito to mock up an AppState object for the purposes of your test.

0

精彩评论

暂无评论...
验证码 换一张
取 消