Microsoft defines Test Driven Development as "Test-driven development (TDD) is an advanced technique of using automated unit tests to drive the design of software and force decoupling of dependencies. The result of using this practice is a comprehensive suite of unit tests that can be run at any time to provide feedback that the software is still working. This technique is heavily emphasized by those using Agile development methodologies".
So from the definition it
is clear that TDD is based on automated unit tests. To continue with
TDD we have to know Unit Testing. Before going deep into the Unit
Testing , we will look into the concept of TDD little more...
The principle of Test
Driven Development is Red => Green => Refactor.
In the above figure, the
development or the coding is start by writing the unit tests. It
fails for the first time as there is no code to compile. It fails for
the second time also because of lack of logic specified in the unit
test. Whenever a test fails, the unit testing framework will indicate
it by the Red signal. And when the test passes it will be indicated
by the Green signal. That is why Red => Green => Refactor
becomes the mantra of Test driven development.
What is Unit Testing?
A unit test is an
automated piece of code that invokes the method or class being tested
and then checks some assumptions about the logical behavior of that
method or class. A unit test is almost always written using a
unit-testing framework. It can be written easily and runs quickly.
It’s fully automated, trustworthy, readable, and maintainable.
A good unit test should
have the following properties
- It should be easy to implement.
- It should be automated and repeatable.
- Once it’s written, it should remain for future use.
- Anyone should be able to run it.
- It should run at the push of a button.
- It should run quickly.