To mock or not to mock the argument of the testing function?
up vote
-1
down vote
favorite
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?
unit-testing testing mocking
add a comment |
up vote
-1
down vote
favorite
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?
unit-testing testing mocking
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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?
unit-testing testing mocking
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?
unit-testing testing mocking
unit-testing testing mocking
asked yesterday
Lu Tran
486
486
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Since person
is complicated to mock, the test for calculateHealth()
prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person
, i should define the interface more clearly, and preferably simple to use and to mock/test.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Since person
is complicated to mock, the test for calculateHealth()
prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person
, i should define the interface more clearly, and preferably simple to use and to mock/test.
add a comment |
up vote
0
down vote
Since person
is complicated to mock, the test for calculateHealth()
prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person
, i should define the interface more clearly, and preferably simple to use and to mock/test.
add a comment |
up vote
0
down vote
up vote
0
down vote
Since person
is complicated to mock, the test for calculateHealth()
prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person
, i should define the interface more clearly, and preferably simple to use and to mock/test.
Since person
is complicated to mock, the test for calculateHealth()
prove to be difficult. This is a design smell and not the test problem. Instead of passing in a black box person
, i should define the interface more clearly, and preferably simple to use and to mock/test.
answered 11 hours ago
Lu Tran
486
486
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349246%2fto-mock-or-not-to-mock-the-argument-of-the-testing-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown