为什么这个 EasyMock 测试失败?
您好,我下面的测试失败了,并给了我这个错误,失败是在验证上...但我不明白为什么。
java.lang.AssertionError: 验证时预期失败: 调试(isA(java.lang.Object)):预期:1,实际:0
测试代码是这样的。
public void testLogInfo()
{
JDBCAppender jdbcAppender = createNiceMock(JDBCAppender.class);
Logger logger = createNiceMock(Logger.class);
LogDB logDB = new LogDB(null, null, null, LogDBDriver.ODBC, Level.TRACE);
logDB.setJdbcAppender(jdbcAppender);
logDB.setLogger(logger);
// method call
logger.info(isA(Object.class));
expectLastCall().once();
// replay
replay(logger);
replay(jdbcAppender);
// verify method call
logDB.log(Level.INFO, "10", "Server", "admin", "shortext", "longText","className","methodName");
verify(logger);
}
Hi I have this test below failing and giving me this error, the fail is on the Verify... but I can't get why.
java.lang.AssertionError:
Expectation failure on verify:
debug(isA(java.lang.Object)): expected: 1, actual: 0
The test code is this.
public void testLogInfo()
{
JDBCAppender jdbcAppender = createNiceMock(JDBCAppender.class);
Logger logger = createNiceMock(Logger.class);
LogDB logDB = new LogDB(null, null, null, LogDBDriver.ODBC, Level.TRACE);
logDB.setJdbcAppender(jdbcAppender);
logDB.setLogger(logger);
// method call
logger.info(isA(Object.class));
expectLastCall().once();
// replay
replay(logger);
replay(jdbcAppender);
// verify method call
logDB.log(Level.INFO, "10", "Server", "admin", "shortext", "longText","className","methodName");
verify(logger);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚发现出了什么问题。
方法调用 LogDB.log 不是调用 Logger.info(Object),而是调用 Logger.log(Priority, Object)。
这就是为什么重播后,状态不一样,因为它期待一种呼叫并接收另一种呼叫。
Just found out what was wrong.
The method call LogDB.log was not calling Logger.info(Object) it was callig Logger.log(Priority, Object).
That's why after the replay, the state was not the same, as it was expecting one kind of call and receiving another.