【发布时间】:2016-06-09 05:12:35
【问题描述】:
class ArgumentClass{
int var;
}
class ClassMocked{
int aMothod(ArgumentClass argumentClass){
return anInt;
}
}
class MyTest{
Mock and Stub here
}
在 MyTest 中,我想对 aMothod 进行存根,以便它根据 ArgumentClass.var 的值返回值。我必须一口气完成。 换句话说,我有一个测试用例,其中应用程序代码调用了 3 次 moehod,并且基于参数对象中的变量,我需要不同的返回值。我需要相应地存根。如果有办法请告诉我。
【问题讨论】:
-
您应该提供更多关于您想要的测试和模拟方法的预期结果的信息。例如,您可以致电
when(mock.aMethod(any())).thenReturn(1,2,3),但我对您的方案了解得不够多,无法知道这是否是您所需要的。