0
在我测试的类中,有一个私有方法实例化Unirest中的GetRequest类。我如何使用Mockito,以便getResponse()中的GetRequest类的实例化产生我在JUnit测试中使用的模拟对象?Mockito在一个私有方法中嘲弄对构造函数的调用
public ClassUnderTest {
public String methodToTest() {
String url = "http://localhost:8080";
String result = getResponse(url);
return result;
}
private String getResponse(String url) {
GetRequest getRequest = new GetRequest(HttpMethod.GET, url);
... = getRequest.header(...).headers(...).asJson();
...etc...
}
}
谢谢 波多黎各
...等...真的吗?你的工作在哪里?你尝试过什么吗? – want2learn
试图看Mockito网站和谷歌搜索。经过几个小时的不成功,我想我会在这里提出一个问题,然后着手做更多的研究。如果我找到可行的解决方案,我会发布答案。 – user2939305
[Mockito:如何验证在方法中创建的对象上调用方法?]的可能重复(https://stackoverflow.com/questions/9841623/mockito-how-to-verify-method-was-called-on -an对象创建中之方法) –