Take the 2-minute tour ×

I know unit test suites exist for Android, Blackberry, Windows Phone, etc.

I have some experience in writing unit tests in Java using JUnit, and C++ using CppUnit.

Why would one want to write a unit test for a mobile phone? For example, why not just use JUnit to test Android and BlackBerry code? Is it because both devices have device specific APIs that cannot be tested using JUnit?


Edit: Links: http://iterativo.wordpress.com/tag/blackberry-bunit-unittesting/

share|improve this question
Unit testing on mobile devices? Links please, it might help potential answers. –  joshin4colours May 28 '12 at 20:37
Added a link to bunit testing –  Gregorio Di Stefano May 28 '12 at 20:49
Good question. Hasn't unit testing meant for tests that isolate a unit from any dependency, even the runtime environment (mobile in your case)? Is it still "unit test" by definition? –  dzieciou Jun 2 '12 at 9:18
add comment

2 Answers

I am not a developer of any of these platforms (only iOS), but I can think of one reason: device hardware:

  • Your tests may run on your computer with computer's performance (multicore with few gigs of ram). Most mobile devices (some already do have dual-core processors and up 2GB of ram) do not have such parameters (yet). This way unit tests may be used to find bottlenecks in low-level code of the application.
  • I am not sure about Blackberry, Android or WP, but iOS does not give access to camera device from the code when it's being run on the simulator.
share|improve this answer
I'm no expert as well but this is what I was thinking. Mobile devices are drastically from desktop/laptops in terms of hardware and networking, so this sounds like a good answer. –  joshin4colours May 29 '12 at 14:00
I am an expert, and your reasons are good guesses. Performance is so divergent (for iOS, the simulator is faster; for Android, the emulator is much slower) as to be useless for insight into real-world scenarios. We get tons of spurious "failures" that are, in reality, induced by the very slow nature of the emulator; on iOS, we would see "failures" of things to exist that didn't happen on device. Furthermore, your theory on hardware not existing is mostly correct; you can fake some of it, but if you're running 90% of your tests on device, getting the last 10% over is usually worthwhile. –  user2136 May 29 '12 at 20:55
add comment

Great question.

Performance is not a serious reason: performance is important, and can differ between devices, but specific performance tests and benchmarks are more effective than test suites.

We derive most of the value from plain unit tests that run in a regular environment, not a device or an emulator. We mock out the phone's library (this can be hard at times but we still find it considerably more effective).

Tests that run on the phone or in an emulator are effective when you encounter integration problems with the actual hardware or other installed software. If you don't encounter it much, the value of these tests is low. If such integration issues are prevalent in your domain, you won't be able to live without them.

share|improve this answer
Agree. Unit testing should be designed to isolate functional issues at the lowest possible level (individual functions/methods) so we derive the most value from unit tests during development (emulator), not necessarily on devices (although we also run unit tests as part of our complete test suite on devices also). –  Bj Rollison Jun 12 '12 at 14:09
add comment

Your Answer


