Test-Driven Development

Test-Driven Development (TDD), is a software discipline in which we write an automated test case before we write any code. It is a principal practice of Extreme Programming. 

The basic pattern is as follows:

The first step is to write an automated test case for the next piece of simple functionality we intend to implement. The test will fail because we haven't written any code to fulfill it yet.

The next step is to write the most straightforward code implementation to fulfill the test and make it pass.

The final step is to refactor the code so that it meets our coding and implementation standards.

When using refactoring with TDD, they make a powerful ally. The TDD test suite enables us to take the refactor step with the confidence that the behavior hasn't changed, as we make the code simpler and more in keeping with the system design.

So, if we're using a Model-View-Controller (MVC) framework, then while refactoring our code, we would be ensuring our newly-added functionality is in keeping with the framework's principles.

For example, our quick cut of code to make the test pass may have left some business-related logic in our controller code. During the refactoring step, we would move this code so that the model handles our business rules. This maintains the separation of concerns called on by the framework we're using, and also makes our software more understandable to anyone coming through behind us (including ourselves).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.191