【发布时间】:2021-02-10 11:00:43
【问题描述】:
jmockit 1.46 版 爪哇 1.8 简单的代码如下:
class PhoneControllerTest{
@Tested
PhoneController phoneController;
@Injectable
IPhoneService phoneService;
....
public void testMethod(@Tested Map map){
new Expections{{
// example 1.mock success when param is
// primitive
phoneService.call("12345");
result="0";
//example 2 .mock fail when param is
phoneService.call(map);
result="0";
}}
}}
interface IPhoneService{
String call(String id);
String call(Map map);
}
我对example2感到困惑,为什么它返回null而不是0?我应该怎么做result在example2中运行良好。 @injectable 对“结果”有影响吗?
【问题讨论】:
-
您在
Expectations中输入的Complex对象可能不等于您稍后在测试中输入的对象。你能展示完整的示例代码和Complex类吗?否则它只是在猜测可能出了什么问题。 -
我已经更新了代码。谢谢