Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I practice Test Driven Development and how should I start?

Tags:

tdd

testing

Lots of people talk about writing tests for their code before they start writing their code. This practice is generally known as Test Driven Development or TDD for short. What benefits do I gain from writing software this way? How do I get started with this practice?

like image 678
Mike Minutillo Avatar asked Aug 07 '08 02:08

Mike Minutillo


People also ask

Why do we need test-driven development?

Test-driven development is increasingly widespread and there is good empirical evidence that it's a beneficial practice. TDD reduces the number of bugs in production and improves code quality. In other words it makes code easier to maintain and understand. Also, it provides automated tests for regression testing.

When using a test-driven development TDD approach what should be done first?

9. Summary. Test-driven development (TDD) is a development technique where you must first write a test that fails before you write new functional code.


1 Answers

There are a lot of benefits:

  • You get immediate feedback on if your code is working, so you can find bugs faster
  • By seeing the test go from red to green, you know that you have both a working regression test, and working code
  • You gain confidence to refactor existing code, which means you can clean up code without worrying what it might break
  • At the end you have a suite of regression tests that can be run during automated builds to give you greater confidence that your codebase is solid

The best way to start is to just start. There is a great book by Kent Beck all about Test Driven Development. Just start with new code, don't worry about old code... whenever you feel you need to refactor some code, write a test for the existing functionality, then refactor it and make sure the tests stay green. Also, read this great article.

like image 74
Mike Stone Avatar answered Oct 11 '22 12:10

Mike Stone