vendredi 16 novembre 2018

To mock or not to mock the argument of the testing function?

Let's say i want to test a function calculateHealth(person) . And let's say the function take a person model argument and return a number from 0% to 100% depending on how healthy the person is. Lets say the person model is costly to create since it has many properties and sub models which also have many properties. I feel like i should mock the person out and substitute it with a simpler version of a person that only behave enough to test my calculateHealth() function. But according to an expert's oppinion (Justin Searls – Please don’t mock me - https://www.youtube.com/watch?v=Af4M8GMoxi4, at 28:14 ) it is a smell if we mock the model value out( for him, it is only ok to mock out dependency but not the model value )

If i have more test like this, it is costly to maintain them if my person model change. What is your opinion?

Aucun commentaire:

Enregistrer un commentaire