【发布时间】:2018-04-27 16:10:22
【问题描述】:
我正在为类“classA”中的方法“methodA”编写一个 Junit 测试。在“methodA”中,调用了“classB”类的另一个方法“methodB”。 'methodB' 调用肥皂网络服务。我想模拟这个methodBsoap 网络服务调用。在这种情况下,我打电话给classA.methodA。在这里,我找不到在调用 classB.methodB 时应该更新模拟值的方法。我浏览了许多关于Mockito 的链接,但它们都指仅从junit 类更新模拟值。那么,我怎样才能通过嘲笑他们的价值。
@Test
public void junitTest() {
String arg1 = "arg1";
classA aObj = new classA();
aObj.methodA(arg1);
}
public classA {
public string methodA(String arg1) {
classB bObj = new classB();
bObj.methodB();
//somwthing on arg1
return result;
}
}
public classB {
public list methodB() {
//web-service call
return list from web - service.
}
}
【问题讨论】:
-
欢迎来到 Stackoverflow!请检查FAQs on Asking并使其成为Minimal, Complete and Verfiable Example(MCVE)