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.
精彩评论