views:

122

answers:

1

After following some instructions on Diego Torres blog I am able to test my classes using the regular Eclipse JUnit test-runner, however I also want to be able to run my unit tests from within the emulated android environment.

For now this should make no real difference since the classes I am working on do very basic numerical or networking tasks, but obviously anything which involves the UI or Android API specific functions can only ever be tested on the emulator.

I set up a new run configuration of type AndroidJUnitTest wich uses the android.test.InstrumentationTestRunner, however whenever I fire up the test I get the following error in the console:

[2010-01-09 00:45:23 - Pal1]Uploading Pal1.apk onto device 'emulator-5556'
[2010-01-09 00:45:23 - Pal1]Installing Pal1.apk...
[2010-01-09 00:45:25 - Pal1]Success!
[2010-01-09 00:45:25 - Pal1]Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5556
[2010-01-09 00:45:27 - Pal1]Test run failed: Unable to instantiate instrumentation ComponentInfo{org.stodge.traderpal/android.test.InstrumentationTestRunner}: java.lang.ClassNotFoundException: android.test.InstrumentationTestRunner in loader dalvik.system.PathClassLoader@43598c28

As you might expect, the test ends (without actually having run any tests after the final "Unable to instantiate instrumentation ComponentInfo" message.

For now my test-cases consist of nothing more than Junit3 and Junit4 boiler-plater code. The implementations of the tests consist of nothing more than fail() calls. All I need to do at this stage is show that I can execute a basic unit-test in both environments so that I can begin test-driven development.

Notes: - Running Eclipse 3.5 on Ubuntu 64bit - Emulator is set to API level 2 - I'm new to both Android and Java, so excuse my basic questions

+2  A: 
Christopher
Do you know if the android test-runner can run classes derived from junit.framework.TestCase?
Salim Fadhley
Yes, that works too. Just "run as" Android JUnit Test as above.
Christopher
And do you know if the android test-runner can handle Junit4 style test-cases or is it strictly Junit3 compatible?
Salim Fadhley
I think Android embeds JUnit4.. I've used annotations on tests, which I think is a JUnit4 feature? Best way to find out is to try! :)
Christopher