KAsiUNblog

Unkasoft's blog, where we talk about mobile games development, gaming industry, agile methodologies and all that matter we're handling every day

Thursday, May 25, 2006

TDD and Eclipse

During our daily work we try to develop our software following eXtreme Programming practices, and specially Test Driven Development (usually called TDD). I said "try", because sometimes it isn't so easy applying TDD in order to fix bugs or work with not-so-clean allready-written code. However, TDD works great for new classes, specially if you use Eclipse.

Lets give a silly sample: we need to develop a "Device" class, which should have an identifier, a description, a copy constructor and one method which sais us whether this device supports a specific audio format (basing on UAProf or WURLF data base).

We can approach this problem from three different ways:Well, the thing is Eclipse gives us a group of tools which can helps a lot if you apply TDD.


Let's start coding the typical template code for one test case with JUnit, and we'll see that Eclipse will mark a lot of compilation errors. As we can see in right image, it says us "Device" class hasn't been found (it's natural, because this class doesn't exists yet). Double clicking over this red error mark, let's see a list with all possible solutions for this error, and among them: create new Device class. So we let Eclipse doing its work and create "Device" class for us, and we can continue with our tests.

After coding two test methods, we're in the same problem: we've several compilation errors, because we're calling methods which don't exists yet.
For instance, we've a test that checks our copy-constructor, and this constructor doesn't exists yet (neither all setters), so we click over error mark at left margin, and choose "Create constructor Device(Device)" option. With the rest of the compilation errors we perform in a similar way, although there will be some situations in which you should complete or change data types for some parameters which Eclipse isn't capable to deduce.

This way, we can achieve Eclipse works for us generating all templates for our classes and methods, basing on all calls we made in the tests code. And this can save us a lot of time.

Once we have all templates written by Eclipse, we can continue coding all logic code in order to get all tests passing (I suppose Eclipse couldn't help us in these tasks :)

Comments:
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?