【发布时间】:2017-12-08 10:17:06
【问题描述】:
我正在使用 spock 框架为我的 groovy 类运行我的 Junit 测试用例,我正在使用 Mock 来调用我的类。但它给了我MissingMethodException,但如果我通过正常创建对象def obj = new MyClass() 调用相同的方法,它正在工作。请让我知道我错过了什么吗?下面是我的堆栈跟踪
Expected no exception to be thrown, but got 'groovy.lang.MissingMethodException'
at spock.lang.Specification.noExceptionThrown(Specification.java:119)
at .AsplTest.fetchXmlTest(AsplTest.groovy:35)
Caused by: groovy.lang.MissingMethodException: No signature of method: com.webservice.Service.fetchAsplXml() is applicable for argument types: (java.lang.String, groovy.net.xmlrpc.XMLRPCServerProxy, java.lang.String) values: [3c98fa0dd1b5d92af599779bfb7be655, groovy.net.xmlrpc.XMLRPCServerProxy@797b0699, ...]
Possible solutions: getFetchAsplXml()
at .AsplTest.fetchXmlTest(AsplTest.groovy:33)
下面是我的测试代码
public void fetchXmlTest() {
given:
def asplObject=Mock(Service);
when:
asplObject.fetchXml(sessionId, serverProxy, "https://serverproxy")
then:
noExceptionThrown()
}
仅供参考: 我的 groovy 版本是 2.4.12 和 spock 版本 1.1-groovy-2.4
【问题讨论】:
-
您正在模拟一个名为
object的变量,然后调用asplObject.fetchXml?试试object.fetchXml -
哦,对不起,这是我的错字。代码正确更新。更新了代码
-
请提供完整的代码。显然,从您的错误消息中,我们需要知道
com.webservice.Service.fetchAsplXml和 sessionId, serverProxy 是什么。 -
我认为
Service没有带有这些参数的方法 -
@tim_yates 它在那里是因为当我调用普通类对象时它正在工作
标签: unit-testing groovy spock