To put it in the simplest terms, IMO testing of which method does not can be very slippery, as you can come up with more and more scenarios when you think about it. Going the other way, claiming that your code does what you intended to do is pretty much the goal of unit testing.
There are two simple questions that usually help me identify a suspicious test and find out if it makes any sense:
- What part of the desired functionality is testing?
- what simple change can i make in test class to break test?
Note that it is extremely simple to solve these issues having a second test ( _CorrectCount ). We really did not see the code of the Add method, but we can most likely get a decent assumption of what could have been changed to interrupt this test. Proven functionality is even more obvious. The answers are intuitive and seem quick (which is good!).
Now try to answer these questions for the first test ( _NoException ). It immediately raises new questions (Is working code real functionality? Isn't that obvious? Isn't that implied? Isn't that what we always strive for? Why is there no statement at the end ??). On the second question, this is even worse - breaking this test is likely to require a clear exception exception ... that we all agree not to go.
Conclusion
Simple The second test is a great example of a well-written unit test . It is short, it checks one thing, it can be easily understood. The first test is not . Even in that it is just as short and (it seems) simple, it introduces new questions (while it really should answer already stated - does Add add?). - and as a result brings unnecessary complexity.
km Jan 9 2018-12-12T00: 00Z
source share