我想为mongotemplate函数调用编写单元测试。我不确定如何写,我只在Web上看到过集成测试用例的实例。
public Class customerById(String id) {
Query query = Query.query(Criteria.where("id").is(id));
return template.findOne(query, Class.class);
}
答案 0 :(得分:1)
您可以尝试类似的操作,只需修改类名
@Test
public void can_find_customer_by_customerId() {
String id = someString(9);
Customer Customer = mock(Customer.class);
given(template.findOne(Query.query(Criteria.where("id").is(id)), Customer.class)).willReturn(Customer);
Customer actual = factory.customerById(id);
assertEquals(actual, Customer);
}