In the test project for my android app I initially had a series of test for several low level classes. By low level I mean that they are not activities, services or anything specific. They are just classes performing some work according to specs. They relay though on some information from the app context – database, some resources etc.
All tests were green and I was happy. After I added another test class to the lineup to test an Activity all of the sudden my green test started to fail. The Activity tests I added are green but some of the tests which used to be green now throw an exception.
From the dalvik trace it looks like that although my used-to-be green tests do not need anything but the application context, the system still tries to resume some activity (not the one I was trying to unit test with the new tests).
So here is my question: how can I unit test a class which needs just the application context but nothing else? How can I prevent the runtime from trying to launch activities I care nothing about?
Is sounds like you want to strip out Android from your unit tests. It would be nice if you could use Mocks for this, but unfortunately if you get the Android framework involved, you run into all sorts of problems trying to mock things.
I highly recommend you use Robolectric to “defang” android, and use Mockito to mock stuff you don’t care about. This will allow you to continue to run your unit tests (I’m making an assumption here) on the JVM.