I saw many people having a wrong idea about tdd. Many people thinks it to develop a code first and then write code that tests its validity. But, in real, they are wrong. Actually, Test Driven Development, or TDD, is a software development technique that is made up of short iterations where tests are written first and then code is written to satisfy the test condition. To use a more concrete example, if we wanted to write a method to validate an email address, we would write the test first that covers this use case and then write the method to make the test pass.
The very basic TDD life cycle consists of the following sequences:
1. Add a test: Create a test to satisfy a requirement. In our example, we would create a test that
calls the email validation method with an invalid email address.
2. Run the tests: Since we haven’t written any code, the test should fail. This is an important step because it validates that the test won’t always pass, which would make it worthless. Initially, you can’t even run the tests because you will have compiler errors, since you haven’t written the code your test is calling yet.
3. Write code: Write code to satisfy the test condition. In this case, you will create the IsValidEmail method to validate an email address.
4. Run the tests: The tests should now pass. If they fail, then repeat step 3 until they pass.
5. Refactor: Now that the requirement is met, we can refactor our code. Re-run the tests as you refactor the code to make sure that you have not broken anything. The preceding cycle is repeated throughout the development process for each new feature that needs to be added.
Subscribe to:
Post Comments (Atom)










0 comments:
Post a Comment