Saturday, April 12, 2008

Android Developer Challenger: Electron Acceptance and Unit Testing Framework

My first intention was to submit a different application, but in the process of developing this application and trying to apply Test Driven Development and Design techniques, I found that although Google is providing JUnit in Android, it was not fully supported, fully documented, fully whatever.

Some Unit Tests can be run in Eclipse, but you were not be testing on the real target. So be careful on that.

Google also provides application instrumentation code through Instrumentation class. When running with instrumentation turned on, this class will be instantiated for you before any of the application code, allowing you to monitor all of the interaction the system has with the application. An Instrumentation implementation is described to the system through an AndroidManifest.xml's .

In the process of writing my own library and tools, I discovered Phil Smith's positron an Open Source library, so I decided to extend his excellent work and bring some new and missing pieces to the table.

And although positron is the anti-particle of the electron, and they annihilate if collide, take for granted that it's not the idea here, but more the conservation of the energy and the generation of some "visible light and waves".

Featured components

Android Electron Acceptance And Unit Tests
Android Electron Acceptance and Unit Test contains some sample applications and their tests:
  • Temperature Converter
  • Touch Paint
  • Web Activity
Android Electron Test Results
Android Electron Test Results is the application used to display test results.
In this video demonstration, Temperature Converter application is tested and some tests failures are showed, because the temperature conversion function is not yet implemented and returns always zero, as an step in the Test Driven Development process.



There's also a web service like interface to drive the tests, as showed in this video.




Electron-JavaSE
Electron Java SE version to drive the tests from the development environment. The ZIP contains the needed components to run Electron, Javadocs and some sample test scripts.

Tests can be scripted, and for example, the test we saw in the video demonstration before can be written as

#! /usr/bin/env electron
start?package=com.codtech.android&\
class=com.codtech.android.adc.tdd.TemperatureConverterActivity

press 123
DOWN
DOWN
CLICK
@celsius.text
assert 123
@fahrenheit.text
assert 253 123C_=>_253F
finish
Stay tuned. More on Electron later.