I am writing my first Android database backend and I\'m struggling to unit test the creation of my database.
Currently the problem I am encountering is obtaining a va
You should use ApplicationTestCase or ServiceTestCase.
Using the AndroidTestCase:getContext()
method only gives a stub Context in my experience. For my tests, I'm using an empty activity in my main app and getting the Context
via that. Am also extending the test suite class with the ActivityInstrumentationTestCase2
class. Seems to work for me.
public class DatabaseTest extends ActivityInstrumentationTestCase2<EmptyActivity>
EmptyActivity activity;
Context mContext = null;
...
@Before
public void setUp() {
activity = getActivity();
mContext = activity;
}
... //tests to follow
}
What does everyone else do?