Daniel Gazineu

15May/100

Test Driven Development and Java ME

At the very beginning of my career as a software developer, I was hired to work at a pioneer company on the field of wireless software. There I learned Java ME (J2ME at that time) almost at the same time I learned Java itself. As a newbie programmer, I was not aware of the benefits of a good code design, neither familiar with methodologies like TDD, DDD, etc.
After sometime, I left the company and moved from wireless devices to server side, where I was presented to Hibernate, Spring, EJB and all Design Patterns and development methodologies surrounding these technologies. A long time passed and now I am again working at a company that breaths wireless market. Although most of the projects I work have mobile phones as target access point, I spend most of the time building the backend to provide content to these clients. Anyway, now and then I find myself doing some maintenance or adding a new feature to a Java ME application and when this happens, I feel like having a déjà vu.
Even the best Java ME developers that I had the pleasure to work with still do not practice Test Driven Development and believe Dependency Injection is only useful for server side environments. Most of the applications I have seen cannot be easily tested due to large dependency on Java ME libraries and external resources. When I try or suggest refactoring I normally listen something like “it’ll complicate things”, “you’re too much server-oriented, in the mobile world we do not need so many interfaces”. I respectfully disagree.
Dependency Injection (DI) is the best friend of Unit Test. Moreover, every time you instantiate an environment-specific object into a domain class, a Ferrari crashes in Italy. Are you willing to give up automated testing, destroy a friendship and a Ferrari? Using DI you can eliminate dependency from Java ME classes, enable your code to be unit tested and save the World (or at least some time).

I will go deeper in this topic at the JavaOne 2010, where I will show some anti-patterns I’ve seen and discuss how to avoid them.

  • Share/Bookmark