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對象創建中之方法) –