Hi dhelper, thanks for your reply.
There is no way to check if all of the faked methods were called..
Ok, so there are no easy ways. I just want to be sure that I did not overlook something in the documentations.
You are right. My test is a bit complex. The method that I am testing is calling up to 3 methods for each item in the collection that the method gets via its parameter.
There is no way to check if all of the faked methods were called, in fact it can cause a fragile test that would stop to work on every change to the code.
I do not see it as fragile, but tightly coupled. The code and its unit test are IMHO by nature very coupled. When you fake method calls done by the code you are testing, you need to know exactly what the code does.
Image this:
1. You write a method that calls the database (saves some data). You mock that call in your unit test so your unit test is not depended on a database.
2. Later someone makes a little change to the method, by replacing the call to the database with another call to the database (another method).
3. My faked methds is not called anymore and the unit test is still green.
BUT: Now we have a unit test that is “out of sync” with the code. The unit test is now cluttered with code that is never needed, and the unit test now depends on the database (it actually saves data to the database!).
If there was some easy way to verify that all my faked methods was actually called, then the unit test will more likely turn red in step 3 and we will know that a fix is needed. I find that to be a good thing!
(The fix will of cause be to ensure that unit test again is in sync with the code.)
Any opinions on my view of things are most welcome…
... just one small thing:
Both TheseCalls and AssertCalls are not order specific...
Ok. I understand this and your are right. But just to clearify. In some cases the order is relevant. Consider this code:
Using TheseCalls.WillReturn(1)
fake.DoSomething()
End Using
Using TheseCalls.WillReturn(2)
fake.DoSomething()
End Using
The first time DoSometing is called it will return 1 and the second time (and onwards) it will return 2.