- Jojo Baldeo
Test-Driven Development: Avoiding the pitfalls
Developers, hold your horses. Most of us think TDD is a waste of time. Honestly, I am convinced otherwise. In this article, I will provide insights for a successful TDD implementation.
TDD helps in the design. Break user stories into smaller components and develop test cases and test scripts ahead of the development phase. TDD is more a design process than a quality assurance process and is an established technique for delivering quality codes. TDD prevents over-engineering since developers focus on writing codes to pass the test cases and not include other functionalities that are not in the requirements. Most developers are guilty of adding codes they think will be used in the future but is not in the current scope.
What are pitfalls to watch for?
TDD is a very challenging task, and here are the typical individual and team pitfalls doing TDD:
Selective adaptation. Not everyone on the team practices TDD.
Failing to run tests before code check-in and after refactoring.
Being lazy to refactor codes.
Failing to perform regression testing.
How to become successful with TDD?
Uncle Bob, Robert C. Martin, the author of the Clean Code book and the founder of the Agile Manifesto, provides three laws of TDD:
You must write a failing test before you write any production code.
You must not write more of a test than is sufficient to fail or fail to compile.
You must not write more production code than is sufficient to make the currently failing test pass.
He also describes the micro-cycle that experienced TDD follows. The Red/Green/Refactor cycle. The three cycles are:
RED - Create a unit test that fails.
GREEN - Write production code that makes the test pass.
REFACTOR - Clean up the code
What should I do as a developer then?
The first step after requirements engineering is to analyze the problem, consider all input possibilities, and determine the required output.
Setup your tools, toolchain, and your IDE.
Develop an application library for your project.
Don't write your test codes. QA people must write test codes.
Maintain version control.
A product that did not go through an extensive quality assurance process is bound to fail. In agile software development, developers release features that require testing to ensure it meets functional requirement and usability.
Uncle Bob: The Cycles of TDD
Andrea Koutifaris: Test-Driven Development What it is and what it is not
Kent Beck: Test-Driven Development by Example
Mohamed Taman: Test-Driven Design Java
Agile Alliance: Agile Alliance Web Site