groovy を使用して Java クラスを単体テストしようとしています。そこには、取得されて呼び出されるHelper
静的メソッドがあります。このクラスを単体テストするために、Groovy テスト ケースでこれをモックしようとしていますが、正しくモックできません。HttpClient
executeMethod
httpClient.executeMethod()
以下はJavaクラスです
public class Helper{
public static message(final String serviceUrl){
HttpClient httpclient = new HttpClient();
HttpMethod httpmethod = new HttpMethod();
// the below is the line that iam trying to mock
String code = httpClient.executeMethod(method);
}
}
Groovy からこの静的メソッドを単体テストする方法についてのアイデアはありますか? オブジェクトはクラス メソッド内にあるためhttpClient
、Groovy テスト ケースでこのオブジェクトをモックするにはどうすればよいですか?
これは私がこれまでに持っているテストケースです。私はnullにモックしようとしていますが、起こっていません...
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)
}
}