As my unit test base gets larger, the main reason of failure becomes out-of-date tests that need to be updated to match the design. In the messy middle portion of the project, I realize that I spend more time updating tests than fixing bugs found by my tests. There is so much oscillation that I'm on the verge of loosing hope and think about abandoning unit tests. If I persevere, I eventually reach a point where all my tests pass, but it takes a lot of will power. That is for me the main unit test challenge.
- How do you know if you have good coverage for your new code? Try removing a line or a constraint check. If all tests still pass, you don't have enough code coverage and you probably need to add another unit test.
- Testing only public members leads to tests that can withstand constant code refactorings and internal implementation changes, while still making sure the overall functionality stays the same.
- When approached poorly, unit tests can achieve the opposite results, stealing valuable time and complicating the testing process.