我正在尝试测试此方法,以查看是否在不带参数的情况下调用了 searchProfile:
public void searchProfile(Long searchTerm) {
this.searchTerm = searchTerm;
searchProfile();
}
public void searchProfile() {
//...
}
这是我的测试用例,我用一个参数调用方法,并期望调用没有参数的方法
@Test
public void testSearchProfile() throws Exception {
CustomerProfileController sutStub = Mockito.mock(CustomerProfileController.class);
doNothing().when(sutStub).searchProfile();
sutStub.searchProfile(0L);
verify(sutStub, times(1)).searchProfile();
}
我怎样才能使这项工作?现在它只是给我一个错误:
Comparison Failure:
Expected: customerProfileController.searchProfile();
Actual: customerProfileController.searchProfile(0);
最佳答案
你应该使用
Mockito.when(sutStub.searchProfile(Mockito.anyLong())).thenCallRealMethod();
准备模拟时。
关于java - Mockito java - 使用不同参数的测试方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886026/