My First steps in Test Driven Development- A Win-Win strategy

Agile practitioners talk about Test Driven Development(TDD), so do lot of developers who care about their code quality and workability. And I once upon a time, not so long ago managed to read about TDD. The crux of TDD as I have understood is:
- Write Test, and fail
- Code, make the tests succeed
- Automate the tests
- Refactor the code to improve the quality
- Repeat
Pretty easy to understand. A annoyed developer shouts- “A developer writing tests? How can you expect us to develop and test and yet finish the feature in time?”. After all developers dont want to do the boring testing work. I have been a developer for around 2 years know and there were times when I reacted that way, during those initial days. But with time, I have started to understand the crux of software development. And this time around I thought of trying out TDD.
My work involves wiring up the data in the db with the UI using an Java EE web framework- A typical web application work.
Let me explain my testing strategy before I adopted TDD:
- Write the complete code which includes- PLSQL procedures, Java code to invoke PLSQL procedures, Java code for the UI bindings and the JSP page itself.
- Manually test the functioning of the db layer and the UI layer code. It involves navigating to the page and then testing various operations. In this case both the UI issues and the Backend code issues would crop up.
- As I would play around with the UI further, I would unearth few bugs in the code, otherwise write a selenium test to automate testing of a few use-cases.
With the above 3 steps, I spent a lot of time-
- waiting for the backend code to compile and the restart the server for the UI to reflect the changes. Even if its a simple 1 word/1 statement change I had to wait for approximately upto 5 minutes and in some cases 8 minutes. While I would wait for this to restart, I would have lost focus to some other task and there by take sometime to come back to the main task.
- trying to debug and find out if the exception/bug is due to the UI code issue or the backend code issue.
- in waiting for the pages to load and navigate through the pages to the right page.
Ok, those were the pre-historic times. Now coming to the Modern Age. I thought TDD would not have been possible in the kind of work I do, it was because I wrote a badly coupled backend and UI code. I couldn’t think of ways to test my back end code independently and then move to the UI code and then test it via selenium tests. Keeping aside these notions, I gave it a shot. I know I wasn’t very close to the actual TDD, but I felt somewhat closer.
- I had a fair idea of how to implement the logic, created a basic implementation and let it compile successfully.
- Created a few data population tests to get the kind of data to be used for the testing.
- Created JUnits to tests the basic functionality. Mostly in terms of the correct execution of PLSQL procedure via the Java API.
- Updated the JUnits to add more tests to test out the actual functionality required and updated the code to implement those functionalities.
- Refactor the code to remove bad smells and then run JUnits to see to it that nothing is broken.
The reasons why I felt excited, why I felt it was a Win-Win strategy:
- I began to think in terms for the user of the API more than its creator. This kept me away from adding hacks which could fix the issue but would be difficult to test. This tremendously improved the code structure then what I had written before.
- No server restarts, no wasting of ~ 8 minutes per restart, no wasting of navigating to the pages. I just had to edit the code, run the junits and see the tests decide the fate. This is more useful for the backend code I have written.
- No loss in focus as I am deeply involved in Code-Test cycles.
- Sense of achievement as I see the tests show up green bars.
- Possibility of creating a code with good unit tests to test the backend features, which also helps in refactoring the code more easily.
Now I just have to write the glue code for the UI and the backend and test the glue code via the selenium tests.
Anyone had any similar experiences when they started to use TDD?
[ Image Source: http://www.doolwind.com/blog/]
No related posts.
2 Responses to My First steps in Test Driven Development- A Win-Win strategy
Connect to us …
Archives
- May 2013 (9)
- April 2013 (6)
- March 2013 (6)
- January 2013 (5)
- November 2012 (2)
- September 2012 (1)
- July 2012 (5)
- June 2012 (1)
- May 2012 (4)
- April 2012 (7)
- March 2012 (2)
- February 2012 (4)
- December 2011 (2)
- November 2011 (4)
- October 2011 (2)
- September 2011 (1)
- August 2011 (1)
- July 2011 (1)
- June 2011 (1)
- May 2011 (1)
- April 2011 (1)
- February 2011 (4)
- December 2010 (3)
- November 2010 (2)
- September 2010 (2)
- August 2010 (3)
- May 2010 (2)
- March 2010 (6)
- December 2009 (1)
- November 2009 (3)
- July 2009 (6)
- June 2009 (3)
- May 2009 (1)
- April 2009 (6)
- March 2009 (1)
- January 2009 (1)
- December 2008 (8)
- November 2008 (5)
- October 2008 (6)
- September 2008 (4)
- August 2008 (8)
- July 2008 (19)
- June 2008 (29)
- May 2008 (27)
- April 2008 (11)
- March 2008 (8)
- February 2008 (22)
- January 2008 (3)
Send To Readmill
Send to ReadmillRecent Posts
- Parsing XML using DOM, SAX and StAX Parser in Java
- How to create ADF TreeTable programmatically?
- Book review: The Object-Oriented Thought Process
- How to show links in ADF Messages
- Runtime Polymorphism in Java
- Understanding RowKey values in ADF TreeTable
- Train Wreck Pattern – A much improved implementation in Java 8
- Converting a List into comma separated value string in Java
- A simple application of Lambda Expressions in Java 8
- Template Method Pattern- Using Lambda Expressions, Default Methods
Disclaimer
Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for your support.










[...] My First steps in Test Driven Development- A Win-Win strategy [...]
[...] My First steps in Test Driven Development- A Win-Win strategy from our JCG partner Mohamed Sanaulla at the Experiences Unlimited [...]