Consider a playfield, with various player types (let's say Hunter
s and Animal
s), all moving on the playfield (and doing some other things). E.g., in a unit test for the Hunter
class, there can be such test cases, as a Hunter
collides with an Animal
and a Hunter
collides with another Hunter
. The latter could look something like this.
public class TestHunter {
private Hunter hunter; // SUT
@Mock // <-- should we?
private Hunter hunter2;
// initialization code, not important...
@Test
public void testCollideWithHunter() {
hunter.collideWithHunter(hunter2);
assert(/* something with hunter, not important */);
}
}
Question: should, in this case hunter2
(which is not the target of the tests), be mocked or not?
My conclusion is, that in this case hunter2
is just another dependency (although, it happens to be of the same class as the System Under Test), so it should be mocked. I would therefore be interested especially in hearing counter-opinions, i.e. why hunter2
should not be mocked?