Test Driven Development
Test first !
mercredi 27 mars 2013, par
TDD is appropriate for scientific computing because a computing program is generally composed of a lot of functions whose returned values are well defined and can be easily tested.
- Write a unit test.
- Be sure that it fails (because you have not yet written the function !).
- Write the simplest function that can pass the test.
- Refactor the code (improve the design of the code without changing its behaviour).
- Go to 1.
If a test fails, there is a bug (in the code or in the test !)
If all tests are OK, who knows ?
Tests are like little experiments that try to falsify the program (cf. Karl Popper).
TDD is thus a scientific method for programming.
Writing tests first favours more independent modules.
And you are sure that most of the code will be covered by tests.
- An Approach to Scientific Software Engineering, Bruno Piar.
- Gagliardi, F., Epistemological Justification of Test Driven Development in Agile Processes. Lecture Notes in Computer Science (Including Subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics). Vol. 4536 LNCS. 2007.