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...
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With