Tuesday, January 13, 2009

Unit Testing Android Applications

Unit testing my Android application has put strain on my patience. All of my unit tests are not just one quick key stroke. I already posted regarding mock testing an Android project. Integration tests are another issue. These tests have to run inside the container -- the emulator or phone. I got started writing integration tests by reading this document. You'll find more Android topics discussed at his blog.

I followed Diego's steps to setup the test-specific eclipse project. Then I created an external tool configuration to launch the tests:
The "Functional Tests" run configuration changes the arguments to:
shell am instrument -w -e func true com.wilson.android.libary.test/android.test.InstrumentationTestRunner
Now each time I'm ready to run the tests I need to deploy the main project, the test project -- if they both changed. Now I can use one of the run configurations above to use "adb" to launch the tests.

Be sure to read the official documentation on running instrumentation tests, starting here.

2 comments:

James Wilson said...

please note: I updated to the 0.9.1 release of the Android Dev kit Eclipse plugin and non of this nonsense is necessary. Just run Run As -> Android JUnit Test.

Unknown said...

Hi James,

I still find your post useful.
If for instance you want to exclude the those tests which have @LargeTest annotation the way you described in the post is the only way to do it:

shell am instrument -w -e notAnnotation android.test.suitebuilder.annotation.LargeTest com.mycompany.myproject.test/android.test.InstrumentationTestRunner

There is no such option in Android Junit Test configuration.

Thanks a lot.