Tuesday, June 8, 2010

Tutorial: Test-driven Development

Instructor: Rob Myers

In the traditional software development cycle testing is done at the end of an implementation cycle. That is, one analyzes the problem, designs a solution, and then implements the results of analysis and design. After all is said and done the implementation is tested. Tests include unit, integration, system and acceptance.

Unit testing is the most basic and includes testing the fundamental units of functionality in a module (i.e. subroutines or classes).

Integration testing is one level up and includes testing the coupling of modules. System testing tests all the modules fitly framed together into a running program. Acceptance testing is further verification and validation testing.

Re-running all of these types of tests is called regression testing. Ideally regression testing is completely automated. Even more ideal is an automated build process coupled with automated regression testing. The best of all is a process attached to version control which checks out the code, runs the build, and then run the regression suite – on multiple platforms. This is called continuous integration.

Enter test-driven development…


TDD is an Agile practice for implementation and unit testing. It is a method of code development that includes writing a test first, then coding until that tests passes.

The recipe is:
1. Write one unit test.
2. Build or add to the fundamental unit under test until everything compiles.
3. Watch the test fail!
4. Make the unit test (and all previous unit tests) pass by changing the fundamental unit under test.
5. Refactor, refactor, refactor.
6. Repeat.

During the last part of the tutorial we paired up and practiced TDD. Rob had us implement a Set class. He outlined several requirements of the Set class then had teams follow the TDD recipe until all requirements were completed. My team was the first to finish :-). The guy I paired up with is used Visual Studio 2010 with C#. The .NET framework has built-in unit testing capabilities. (I have been using Google Test for my own Linux based C++ unit testing)

Rob suggests three books:
* Refactoring (Martin Fowler)
* Test-driven Development (Kent Beck)
* Working Effectively with Legacy Code (Michael Feathers)

No comments:

Post a Comment