What is Test-driven development?
Test-driven development (TDD) is a software development process with short, repeated development cycles. The whole idea comes down to testing before a line of code is written. The goal of TDD is to have better design and verify code.
Steps:
- Write- an automated test case that will fail.
- Run- make sure the test will fail for the expected reason.
- Write- code that will cause the test to pass.
- Run- to make sure all test cases now pass.
- Refactor- clean the code up.
- Repeat- the cycle to move functionality along.
A passing test from step 2 will require step 1 to be redone, if the test fails you will continue on to step 3. If on step 4 the test fails you will have to go back to step 3, but if the test passes you will move on to step 6.
What are the benefits?
- Detects defects more quickly
- Decreased use of debuggers
- Detect changes in code behavior
- Code is modularized and flexible
- Cuts down on code implementation time
- Concerned with interface before implementation
- Developers write more tests, are more productive
What are the drawbacks?
- Can be difficult to use
- Can lead to a false sense of security
- Maintenance of tests can be expensive
- One developer can lead to shared blind spots
- Coverage and detail in tests is not easily recreated
- Management might see writing tests as a waste of time
Do you use TDD? What do you feel like some of the benefits and drawbacks are?