Archive for category Testing

T-Mobile Pulse and Testing on Real Devices

tmobileIf you are in the UK then you might like to take a look at T-Mobile’s 20% off PAYG phones today only. In particular there’s the T-Mobile Pulse for only £119.99. This is without contract so the total cost of ownership is very small. I actually use one of these for testing on Android 1.5.

I believe it’s important to test on as many real devices, with different versions of the OS, as possible, especially when programming asynchronous tasks.

The emulators only go so far when testing your applications. I have had several instances where the timing of asynchronous things happening (UI vs something in background) have caused things to happen, depending on the device, in a different order. For this reason, it’s best to test on as many real devices as possible.

Android Java Reflection

reflectionI have recently had to use reflection in Java. It allows you to develop with the latest SDK (say 2.01 or 2.1) while still allowing code to be run on older 1.x devices. Ordinarily, running (calling) newer APIs on older phones would cause errors.

Reflection is essentially a facility to test if an API exists. If it does then you can call the API. If it doesn’t then you can degrade gracefully with an error to the user or do something else instead.

There’s a great article on the Android Developers Blog explaining how it works.  It relies on a call to .class.getMethod() and catching a possible NoSuchMethodException.

Excessive use of reflection and/or not caching whether the api is there and/or using reflection repeatedly in time critical code, can cause performance problems. Also, this extra mechanism makes code less readable and, as more newer APIs become available, might make code harder to maintain.

One of the most useful places to use reflection is in testing. It allows common test harnesses to be built that can be run on both old and new code. Obviously, as it’s only test code, performance is less of an issue.