Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is it OK to change "completed" unit tests?

Tags:

unit-testing

I've taken my first baby steps into Unit Testing and, due to a better understanding of the domain, have made a change to a domain model that has broken a unit test. So this brought up the question:

When is it permissible to change previously working unit tests?

I figure I'm missing an important aspect of unit testing in having to ask this question...

like image 962
I Clark Avatar asked May 06 '09 07:05

I Clark


People also ask

Should unit tests change?

Every time you need to. Tests should be changed if they become inaccurate, or don't follow specs anymore. Tests should be removed if they have become irrelevant.

What does the timely rule of unit testing mean?

Timely: Unit tests should be written just before the production code that makes the test pass. This is something that you would follow if you were doing TDD (Test Driven Development), but otherwise it might not apply. I personally do not use TDD and therefore I always write my tests after writing my production code.

How long is too long for unit tests?

Thus, a unit test suite used for TDD should run in less than 10 seconds. If it's slower, you'll be less productive because you'll constantly lose focus.

When should the testing of the unit be done?

Unit testing is the first software testing phase in SDLC and it is usually taken up during the development of the application. These unit test cases are written and executed by software developers.


1 Answers

For 'proper' TDD you change the test first, then change the code.

So actually you never have broken tests, only broken code. You should always strive to be in a position where the tests are the definitive expression of correct functionality, and as such are, a priori, correct.

like image 141
PaulJWilliams Avatar answered Oct 15 '22 18:10

PaulJWilliams