【发布时间】:2020-08-24 02:29:52
【问题描述】:
嗨,我的班级看起来像这样。
public class Class1 {
public void method1(Object obj) {
// Class 2 makes the restApiCall and result as "SUCCESS" if the HTTP response is 202
Class2 class2 = new Class2();
String result = class2.callRestService();
System.out.println(result);
}
}
public class Class2 {
public String callRestService() {
String url = fetchUrl(System.getProperty(COnstants.URL);
String result = callRestServiceAPi(url); // Calling the RestApimethod.
return result;
}
}
我想为 class1 编写单元测试,并且我想通过实际不调用 RestAPi 来实现它,这意味着我想模拟 class2.callRestService() 方法以返回“成功”或“失败”。怎么可能。
【问题讨论】:
标签: unit-testing junit void