【发布时间】:2018-09-19 01:09:50
【问题描述】:
我是 Jmockit 的新手,我正在尝试使用以下验证来模拟 jdbcTemplate.udpate(),
new Expectations() {{
someRef.flushUpdates();
}};
new Verifications() {{
String query;
jdbcTemplate.update(query = withCapture(), withInstanceOf(Date.class));
times = 1;
}};
flushUpdate 有更新查询,
public void flushUpdates(){
Date now = new Date();
String query = "Update table_name set last_updated = ? ";
jdbcTemplate.update(query,now);
}
测试是验证update查询是否被触发了两次。
但我收到以下错误。
mockit.internal.MissingInvocation: Missing 1 invocations to:
org.springframework.jdbc.core.JdbcTemplate#update(String, Object[])
with arguments: any String, an instance of java.util.Date
on mock instance: org.springframework.jdbc.core.JdbcTemplate@2d000e80
有人知道吗?
【问题讨论】:
-
快速浏览Getting started页面。
-
我在基类和测试类中使用了
@Injectable JdbcTemplate jdbcTemplate;,这导致从Expectation内部类调用时对象引用发生变化。从基类中删除引用解决了这个问题。
标签: java unit-testing jmockit jmock