我想我没有verify
正确使用。这是测试:
@Mock GameMaster mockGM;
Player pWithMock;
@Before
public void setUpPlayer() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
pWithMock = new Player(mockGM);
}
@Test
public void mockDump() {
pWithMock.testDump();
verify(mockGM).emitRandom(); // fails
}
这是它调用的代码:
public boolean testDump() {
Letter t = tiles.getRandomTile();
return dump(t);
}
private boolean dump(Letter tile) {
if (! gm.canTakeDump() || tiles.count() == 0) {
return false;
}
tiles.remove(tile);
gm.takeTile(tile);
for (int i = 0; i < 3; i++) {
tiles.addTile(gm.emitRandom()); // this is the call I want to verify
}
return true;
}
故障跟踪:
Wanted but not invoked:
gameMaster.emitRandom();
-> at nth.bananas.test.PlayerTest.mockDump(PlayerTest.java:66)
However, there were other interactions with this mock:
-> at nth.bananas.Player.dump(Player.java:45)
at nth.bananas.test.PlayerTest.mockDump(PlayerTest.java:66)
我要验证的电话是几层。有没有不同的方法来检查这个?