TDD in Agile



Best Practices for Agile Test Driven Development

Test Driven Development (TDD) is a minimalistic software development process that is driven by an automated test case which defines the desired enhancement to the system. The test is first executed to fail. The developer then comes up with a minimal code that will pass the test case. Once the new code is tested, it is refactored to adapt to standards and retested. The cycle is then repeated to add further enhancements.

Designed as an offshoot of extreme programming, TDD follows the agile method of building software in iterations and involves clean, simple designs and code.
We present some of the best practices to be followed in TDD projects:

1. Avoid functional complexity

Keep functionality to be achieved simple. Deliberate on it with the whole team to ensure the test case covers the desired functionality in every way possible. As the test case is the driver here, it should be reviewed for correctness and completeness.

2. Focus on what you need to achieve

Be sure you understand where the code needs to be called and frame the test suite accordingly.  Ensure test cases follow standard naming conventions and clearly depict what needs to be achieved by the end of the development process. This is crucial as functionality keeps getting added with iterations. Future developers should be able to look at the test and easily deduce the intended functionality.

3. Maintain code austerity

Ensure your code has just enough meat to satisfy your test case. This is a basic tenet of TDD. This minimizes the chances of defects and also simplifies review and testing processes. However, do ensure the code is understandable and allows future enhancements.

4. Test repeatedly

Test before coding and after coding. Then test once again after code refactoring. This is to reinforce that no code is broken in any of the steps. During refactoring, ensure the new code is maintainable and adheres to standards. The rule of thumb here is repeat testing whenever there is a code change or code move or code merger.

5. Maintain code sanctity

Use version control tools to check out and check in code. This is important, specifically when more than one developer is working on the code. Using continuous integration tools like Jenkins can avoid code merger issues.

6. Application knowledge

In TDD, coding needs to be limited but effective in that it achieves its purpose without breaking anything else. Also, the new code should ideally pass the test case in the very first run. Maintaining adequate system documentation, including a repository of test cases and engaging team members with good application knowledge can ensure a smooth and successful project execution.

7. Know when to use TDD

Last but not the least, TDD, like any other development concept, works best in certain scenarios. Use TDD for developments that can be quickly tested. Any testing that is prolonged or complex defeats the purpose of TDD.
With TDD, development is more controlled and as a result, defects are considerably reduced. Repetitive testing ensures each component in the system is working correctly at every step. 

Comments