Sorry for the radio silence recently. I've taken a position as a DevOps (my other hat) so have been immersed in the world of Jenkins, Puppet, etc. But my love for Android still exists. :)
Recently I saw a Twitter post about unit testing and it mentioned the phrase "100% reliable". It reminded me of something that happened to me at my previous place where a unit test was passing but the app crashed on some devices.
Take this unit test:
1 2 3 4 5 6 7
It's a noddy test to check that the parsing of a date string gives the correct hour. It runs. It passes.
So we put this code into our activity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Run that on a modern device or an emulator running a recent Android API level. It will be fine and will display "Hour is 19".
BUT...try running it on an emulator that is running API 16. You'll see this:
But hold on. The unit test is fine. It passes. So why the crash? Well it turns out that the 'XXX' formatting instruction was only added in Android 4.3. This is from the java.text package and is not Android specific.
So the moral is that unit tests might not be 100% reliable after all. Ultimately you are running them on the JVM that is installed on the computer that you are developing on, and this is not the same as the JVM that runs on the Android device.
Darren @ Æ