3 ms·
You are forgetting one important part: unit tests serve as an always updated, always tested documentation of how you use the functionalities of your software.
by rbanffy 5y ago
You are forgetting one important part: unit tests serve as an always updated, always tested documentation of how you use the functionalities of your software.
I agree with your point on 3 - you should use the tests to start figuring out how your unit is going to be used. If you write code first, you frequently end up with untestable code that you need to mock the universe to get it running in artificial conditions. I don't recommend writing your tests first unless it's a trivial case, but you should at least have the unit calls in tests before you start coding.
- oxff 5y agoThis has been my interpretation of unit testing for some years now. They should be renamed to "Examples" or "Documentation Test" because all they really do is when I read them is (i) show how to use the unit (ii) and common error / success cases of that unit. I would never really on them for actually testing the expected property of a public API for example.
- rbanffy 5y agoDepends on how extensive the unit tests are. But, again, you also need to do integration tests for making sure you are not getting anything funny from external sources you rely on.