Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't see the point of asserting that getHour has been called in your (admittedly contrived) example. Mocking (or rather stubbing) a datetime library is usually just useful to get a predictable result. Making assertions on what methods get called and how many times seems useless in that case.

Sometimes it can be useful to make this kind of assertions on a mock though. Say you're mocking a web service, you can use this kind of assertion to ensure you're calling the web service properly. In this case it's useful because it's verifying behavior at a boundary between your program and the outside world. That's what I think tests are for. The outside world is not made only of users. Communication with external resources is also important and can be verified with mocks. In other words, this kind of mock assertions is interesting to verify the indirect outputs of the program: http://xunitpatterns.com/indirect%20output.html



I agree. There is no point in adding coupling for it's own sake by asserting that trivial methods are called.

Verification testing does however have it's uses in terms of verifying that key interactions have happened in the way you expect.

In the most part it's used correctly, assertions are much more widely used than verification testing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: