嘿伙计们,我对 junit 测试中的 SqlRowSet 有疑问。有没有人有模拟 SqlRowSet 的示例或方法。向它添加假值并使用它来测试您的方法?我知道我在这里有点含糊,但到目前为止我从未使用过 SqlRowSet,所以这让我感到困惑。谢谢!
问问题
515 次
1 回答
1
有许多用于模拟真实对象的框架,例如Mockito、PowerMockito。下面的代码片段是用 Mockito 编写的。根据您的要求更新测试用例。
@Test
public void testSqlRowSet() {
SqlRowSet sqlRowSet = Mockito.mock(SqlRowSet.class);
JdbcTemplate jdbcTemplate = Mockito.mock(JdbcTemplate.class);
Mockito.when(jdbcTemplate.queryForRowSet(Mockito.anyString(), Mockito.eq(Integer.class))).thenReturn(sqlRowSet);//Change the method parameters accordingly
Mockito.when(sqlRowSet.next()).thenReturn(true);
}
于 2020-04-26T04:56:13.197 回答