【发布时间】:2016-12-13 14:33:59
【问题描述】:
当我从 testclass 运行 class1 中的方法 try() 时,我正在尝试使用 mockito 来模拟 class3 中 method3() 的返回值。我有不能对我拥有的代码进行任何版本的限制。所以,我不能根据我在互联网上看到的一些解决方案添加构造函数来制作模拟。我将 MockMVC 与 WebApplicationContextSetup 一起使用。请指导我是否可以仅使用 mockito 模拟 method3() 的值,如果不可能,我可以用来模拟该值的其他解决方案是什么?
class1
{
Class2 c2 = new Class2();
public String try()
{
Something temp1 = c2.method1();
}
}
class2
{
Class3 c3 = new Class3();
public String method1()
{
return c3.method3();
}
}
class3
{
//Will like to mock the return value of this method
public String method3()
{
return "asd";
}
}
testclass
{
class1 c1 = new class1();
c1.try();
}
非常感谢:D
【问题讨论】:
标签: spring unit-testing spring-mvc mockito mockmvc