且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单元测试来自 Groovy 测试用例的 Java 类中的静态方法

更新时间:2023-11-16 22:32:04

您可以使用

HttpClient.metaClass.executeMethod = {Type name -> doSomething}

您需要使用正确的Type(即String、Map 等)声明闭包签名

You need to declare the closure signature with the correct Type i.e. String, Map, etc.

void testSendMessage(){
    def serviceUrl = properties.getProperty("ITEM").toString()

    // mocking to return null   
    HttpClient.metaClass.executeMethod = {HttpMethod str -> null}
    def responseXml = helper.message(serviceUrl)

}