By now, I hope we can all agree that unit tests are a good idea. I recently gave a presentation on why I think testing before writing production code (TDD) is better than testing after.
Code Quality
Only writing code to fix failing tests yields:
- Better tests
- Testable code
- Decoupled
- Fast
- Less rework
- High test coverage
- Less debugger
- Simple
- Less gold-plating
Continuous Integration
Minimizing time in Red and committing on Green yields:
- Compiling, tested code every ~10 minutes
- Ability to revert to last Green quickly
Improved Interfaces
Intelligent test names and coding from client's perspective yields
- Self-documenting code with clean, natural interfaces
// ๐
GetLog().Debug().Message("My message.");
Log(Priority.Debug, "My message.");
// ๐
void Debug_LogsDebugMessage() {
Log.Debug("My message.");
// Some assert
}
Testing after is work, TDD is fun!
Top comments (0)