vendredi 9 mars 2018

Why do you count the number of times a function gets called in unit test

My new colleague incessantly insist me to count the number of times functions inside a unit test gets called when doing backend unit testing. I can see why it can be helpful at times but for most part I feel that it is redundant and unnecessary. From my perspective, it should not matter what function gets called and how many times it gets called. What matters is what goes in and comes out to check the expected behavior.

Unit testig should be more like a black box as in it doesnt matter how you get the answer, but matters if the answer is correct or not. If I am always validating the number of times some functions gets called, it creates a lot of overhead cost. It also means that everytime I change the approach to solve the problem, my unit test would break and I will beed to fix it every single time. I feel like this approach limits the flexibility of coders.

Can anyone please tell me why these sort of unit testing should be performed? Thank you.

Aucun commentaire:

Enregistrer un commentaire