Testing with Android is a pain.
While the normal JUnit test does work, once one makes a few adjustments to the setup on Eclipse, this does not mean that any of the Android classes are available for these tests. So even if my classes are not Activities, Services etc, but plain old computations, they cannot be tested with JUnit as soon as I make use of any of the classes in Android.
I think that some of this reveals bad design decisions by those developing Android. Take android.graphics.Rect. This is a class that has keeps tab of four corner points plus gives some simple operations such as intersections. There would be nothing Android specific in them were it not for the methods to parcel it for the Android IPC. Would this not have been done better by exposing these methods with standard serialisation mechanisms via a custom toByteArray or some such?
Another solution would have been to have an Android-only jar which contains only the Android classes, with some things suitably stubbed out, so it can be linked into the testing framework on the host machine, rather than the Emulator.
Looks like I have to bite the bullet and make all my testing run on the emulator. At the same time I am making the same mistake as Google: not observing a strict layering principle which will give me much better portability in the future.
I have to go away and think about that.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment