I have two tests they are exactly the same… barring two things, they call two separate service calls.. hence when im using mockito i have two seperate expectation and verify lines…
this is what i have done:
@test
TestA {
baseTest("player");
}
@test
TestB {
baseTest("member");
}
BaseTest(type type) {
....
.....
if type(player) {
Mockito.when(player service call)
}
else {
Mockito.when(member service call)
}
// make the call in code
//verify
if(player) {
verify player specific service call...
}
else {
}
}
I think the above is a test smell… just doesnt feel right…
Is there a better way then placing an If statement in my baste test?
You should develope your test code independenly and join things when they have sense.
By example. One rule of thumb for initialization code (the first A of Arrange/Act/Assert) is that:
So my conclusion is:
In fact @artbristol answer makes sense: if you are using if’s for alternate behaviour consider polymorphism. It’s just I’m not sure until which point it’s complex for test or not (probable it makes sense if the code is testing a similar class hierarchy).