In the JavaDoc of ActivityUnitTestCase it says:
Do not call from your setUp() method. You must call this method from each of your test methods.
Isn’t putting something in every test method equivalent to putting it in setUp, considering that the whole idea behind that method is to do just that, i.e. executing something before every test?
Also, why are we not allowed to do that? I tried it, and it works just fine.
It appears that setUp runs with the test project’s class loader, while the actual test methods run with the app under test’s class loader. See, for example, this discussion on the RoboGuice mailing list:
http://groups.google.com/group/roboguice/browse_thread/thread/2e129f87ead10b10
Why this is the case, I’m not sure (it seems like a very strange design decision to me). But the upshot is that you can’t access anything in the app under test in your setUp method. Which moves setUp into chocolate teapot territory.
Note that this restriction does not apply if you’re testing a library project as described here:
http://www.paulbutcher.com/2010/09/android-library-project-with-tests-step-by-step/
Because in that case the tests and the code under test are all in a single app.