lundi 5 octobre 2015

Why would one want to test if a method is called?

I've seen a lot of examples of how to test if a certain method has been called. But why would one want to do this form of testing? Wouldn't it be more effective to test the outcome of whatever said method is doing?

If I would want to test add(X, Y) just to see if it was called... why would I not just assert that add(X, Y) == X + Y? In that case not only do I verify that the method is being called, but I'm actually verifying what the method is doing in the same test.

Even in the case of testing a method being called X times, say Summation(N) where it would call add N times to get a total of N + N - 1 ... + 0; I still cant see the value in just testing how many times add was called.

Could someone give some helpful advice to a starting Test Engineer to understand this. Perhaps an example of why testing if a method is called is important, and why not just testing its outcome would be more necessary?

Aucun commentaire:

Enregistrer un commentaire