use*_*342 4 java testing mockito
在编写我的测试用例时,我正在使用Mockito来模拟某个类.
有没有办法在返回值之前打印一些语句?喜欢:
when(x.callFunction(10).thenReturn(new String("Hello"));
Run Code Online (Sandbox Code Playgroud)
上述声明有效,但我无法执行以下操作:
when(x.callFunction(10).thenReturn({
System.out.println("Mock called---going to return hello");
return new String("Hello");});
Run Code Online (Sandbox Code Playgroud)
随着thenAnswer您可以执行每次调用模拟的方法时附加的动作.
when(x.callFunction(10)).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) {
System.out.println("Mock called---going to return hello");
return "Hello";
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1751 次 |
| 最近记录: |