Monday, January 19, 2009
Using the right DB increased test coverage 10 times !!!
What support?
- Quickness
- ease of rebuilding
- smooth to handle with a programming language
I worked on an application recently which had no unit tests. When I joined the team I spoke to the team about benefits of tests - both unit and acceptance. The project had good amount automated acceptance tests though.
We tried the idea of in-memory DB - HSQLDB. This is a light weight database made in Java language. Using ANT (with hibernate) we created tasks like -
- generateSchema
- createDatabase
- populateDatabase
- deleteDatabase
Using these tasks we had great control over the DB. Moreover the DB being light and in-memory made writing tests very quick. We even configured it in Cruise Control.
Initially before we started with HSQLDB 10 days back, our test coverage was 3% and now it is 30%, growing exponentially.
Tuesday, December 9, 2008
Debugging Vs Unit Testing
We developers need to win this battle. Ofcource I am on the Unit Testing side and thatz the reason for this battle. We want to improve. We want to stop debugging, or we may call it post coding or post delivery nightmare.
- How may of us are fond of SOPs? [System.out.println]
- How many of us are good a putting / reading log files?
- How many of us are good at using the debugger? Looking up the values inside objects at runtime?
We all are. Because thatz what we do most often. The percentage of time we
spend on debugging is far more than coding.
Every programmer knows they should write tests for their code. Few do. The universal response to "Why not?" is "I'm in too much of a hurry." This quickly becomes a vicious cycle- the more pressure you feel, the fewer tests you write. The fewer tests you write, the less productive you are and the less stable you code becomes. The less productive and accurate you are, the more pressure you feel.
- Programmers burn out from just such cycles. Breaking out requires an outside influence.
- The best way to convince you of the value of writing your own tests would be to sit down with you and do a bit of development.
- Along the way, we would encounter new bugs, catch them with tests, fix them, have them come back, fix them again, and so on.
Wednesday, December 3, 2008
Do we have enough time for testing?
"Delivering Code Without Tests Is A Sin"
This is a punch line by Bob-Martin, I heard in one of his sessions I attended. We already are wasting/investing huge amount of time in injecting bad design and bugs into our applications. So I want to ask this question again -
Do we have enough time for testing?
My question to this question is - Do we have anything to lose?
Lets start writing tests...
Tuesday, December 2, 2008
Post Horrible Mumbai terror attack 26/11..
Some groups, citizen showing a high sense of responsibility.. of worrying about the state of country and people..
Some very irresponsible.. thick skinned..
Everyone around me.. at my work, my friends, my family.. express frustration in various ways about such barbaric terror acts..
I've been thinking around all these thoughts, information revealed.. discussions..
I am a lazy person.. And I know this very well, I publicly accept this. This actually is very helpful in always being aware of this negative quality of mine. As it helps me remain alert at many times. But generally I am lazy about many things..
- my health,
- my plans towards my career,
- maintaining documents,
- filing my tax returns,
- playing with my kid,
- calling my friends,
- wishing my friends happy birthday,
The list goes on..
But still I am leading a very responsible and efficient daily life. I continue taking care of my health, my family, my social responsibilities, my career, my documents... list goes on.
How?
I am part of Cycle Of Life. The way I understand it is, there is a threshold, for every negligence, every ignorance, every selfish act, every uncaring attitude. As soon as the threshold is reached, the alarm goes ringing. I dont really care at the first alarm. But there are series of alarms well set, which keep going on with increasing threshold values. And a time comes when a blast is triggered. The blast is very harmful all the time. I have to pay heavy penalty to my bank for not taking care of my documents, I catch cold/fewer for neglecting my health, my kid starts becomming cranky and unstoppable because I am not paying attention to him...
After the first instance of each blast I start taking care to avoid it to repeat.
Our society behaves in exactly the same way. People all around the world become selfish, irresponsible, careless. If they do not listen to warning alarms they suffer thru the blasts. In the news / papers, I can read a lot about various agencies across different countries showing irresponsible behaviour in executing there duties. Of-course they are all headed by human beings who commit mistakes.
If we see the current scenario around the world, the number of alarm blasts is very high.
- multiple economies going down
- financial crisis
- terrorist activities
- etc...
This will cause damage at various levels. And bring the world below the threshold level of alarms.
I believe, the divine power can help us at the micro-est level to take care of preventing us from doing any negative act.
I wish we sahajayogis are able to convey the vision of Sahajayoga to the world.
Sahajayoga principles are the only way we can always remain below the threshold and keep growing continuously in positive direction.
By Sahayoga principles I mean -
- How can I avoid lying?
- How can I get more strength to forgive?
- How can I only love and never hate?
A beautiful world visioned by Shri Mataji Nirmala Devi. You'll see this coming true if you meet with a group of Sahajayogis.
http://www.sahajayoga.org/
Sunday, November 30, 2008
Plan Of Action - TDD
- Install the measurement tools, like emma, clover, Cobertura, CodeCover
- Learn/understand the project code. Each project may have unique requirements in terms of writing unit tests, like struts, database, containers API, any other API.
- Use FindBug & CheckStyle reports to improve the quality of code.
- Build the initial required framework for writing unit tests, for the ease of rest of team.
- Move from [Code - Test - Debug] => [Test - Code - Refactor] Mode
- Achieve the state of -- Writing a new test should not introduce more overhead than the test itself.
Writing a test makes you ask a lot of questions related to the requirements as well as implementation, which eventually is very helpful to filter out any bugs which may be introduced in the appications otherwise.
What I want to do?
Fortunately I got opportunities to work with & learn from industry experts like Bob Martin, Michael Feathers and Brian Marrick during my tenure in US. All of them and all the software industry experts strongly recommend test driven development as a key approach to improve software deliverables and creating very efficient and highly maintainable software.
We, in our projects, even today try to promote test driven development by writing test cases for the deliverables before we start any development. But unfortunately we write tests in XL sheets and Word documents or even worst we don’t write them at all. Having tests written in documents makes them dead and they eventually get buried in some central document repository. That’s where the dead things go. It is nothing better than not having it.
Due to these reasons the industry experts strongly recommend executable unit tests which can be run in an automated fashion. It requires a great mindset change to start writing tests before the code. We may not see clear benefits until we have at least 30% of code coverage. But still I think we have nothing to lose, as we are already in such a bad shape with the kind of software we build.
So my question to the group is -- should we allow someone to completely dedicatedly focus on this problem?
Now Bob Martin, Michael Feathers and Brian Marrick are not going to come and write code for us. We ourselves have to do it. Fortunately I got opportunities to work with & learn from Bob Martin, Michael Feathers and Brian Marrick during my tenure in US. I can at least talk about, write and demonstrate the importance of Unit testing, what I have learnt from them and then also experienced it myself.
I request the group to give me an opportunity to work for this initiative.
Thank you for reading till this point, a few more points ahead…
What I want to do?
· Be a Unit & Automated Testing Champion
· Spread best practices across projects in ODC
· Work with different team on improving development practices
· Take sessions on TDD, Automated Testing, Checklists, FindBugs, CheckStyle, CI, Emma, Design Patterns, Java, Struts, Hibernate, Spring
· Increase test coverage of each project that I work on.
· Keep continuous track of latest technologies
· Publish ideas in forums like Arch CoE, Wiki
· Contribute to various groups, open source.
My Quantifiable Goals [in 3 months]:
· Increase test coverage of 2 projects by/to 50%
· Conduct at least 5 sessions on software development best practices
· Initiate 5 techies to participate in knowledge sharing
· Share the achievements/learning once a week in Architecture CoE
What am I doing right now?
· Deployments, PRD & QA. Thankfully we have automated deployments for INT.
· Resolve technical queries of team.
· Complete Stories & bug fixes.
· Lots of Coordination activities, part of leading the team.
· Perform all the thankless activities of a Tech-lead.
· Use TDD for whatever I code and spread the word in team.
· Talk about Testing practices informally whenever I get a chance.
· Work with some proactive people to help them with any doubts related to testing practices.
· A few PL related activities like appraisals.
· I have also been told that I am a scrum master for CTB team.
Thank you for reading this, please send your comments.