java로 작성된 클래스에 대한 테스트 케이스를 groovy에 작성하려고합니다. Java 클래스 (이름 : Helper)에는 HttpClient 객체가 얻어지고 executeMethod가 호출되는 메소드가 있습니다. 나는이 httpClient.executeMethod()를 groovy 테스트 케이스에서 조롱하려고하는데, 제대로 조롱 할 수 없다. 다음은 Groovy에서 Java 클래스 조롱하기 테스트 케이스
는 //이 헬퍼 클래스는 자바 클래스를있는 자바 클래스이다public class Helper{
public static message(final String serviceUrl){
----------some code--------
HttpClient httpclient = new HttpClient();
HttpMethod httpmethod = new HttpMethod();
// the below is the line that iam trying to mock
String code = httpClient.executeMethod(method);
}
}
내가 지금까지 그루비에서 작성한 테스트 케이스는 다음과 같습니다 이유에
void testSendMessage(){
def serviceUrl = properties.getProperty("ITEM").toString()
// mocking to return null
def mockJobServiceFactory = new MockFor(HttpClient)
mockJobServiceFactory.demand.executeMethod{ HttpMethod str ->
return null
}
mockJobServiceFactory.use {
def responseXml = helper.message(serviceUrl)
}
}
어떤 아이디어 그것은 정확하게 조롱하지 않습니다. 사전 감사
[이 접근법] (http://thecarlhall.wordpress.com/2010/03/25/unit-testing-with-httpclients-localtestserver/)이 도움이 될 수 있습니다. –