Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How often should we write unit tests?

Tags:

I am recently introduced to the test-driven approach to development by my mentor at work, and he encourages me to write an unit-test whenenver "it makes sense." I understand some benefits of having a throughout unit-test suite for both regression testing and refractoring, but I do wonder how often and how throughout we should write unit-test.

My mentor/development lead asks me to write a new unit test-case for a newly written control flow in a method that is already being tested by the exsisting test class, and I think it is an overkill. How often do you write your unit tests, and how detailed do you think your unit tests should be? Thanks!

like image 932
Midnight Blue Avatar asked Mar 29 '10 13:03

Midnight Blue


1 Answers

Technically, if you're following strict Test Driven Development...you should be writing your Unit Tests after you have spec'd any portion of your application. You should be going from:

User Requirements -> Function Design -> Unit Tests -> Code

Remembers, Tests come before Code in TDD.

like image 74
Justin Niessner Avatar answered Oct 12 '22 02:10

Justin Niessner