Unit testing Grails控制器单元测试方法SelectionException
我有一个单元测试类正在抛出这个奇怪的异常…我不知道它的意思…有人能帮我吗 这是一节课:Unit testing Grails控制器单元测试方法SelectionException,unit-testing,grails,Unit Testing,Grails,我有一个单元测试类正在抛出这个奇怪的异常…我不知道它的意思…有人能帮我吗 这是一节课: @TestFor(ApplicationController) @TestMixin(MvcUnitTestCase) class ApplicationControllerTests{ def init(){ super.init(ApplicationController) } void testCheckOk() { def service = mockFor(ApplicationS
@TestFor(ApplicationController)
@TestMixin(MvcUnitTestCase)
class ApplicationControllerTests{
def init(){
super.init(ApplicationController)
}
void testCheckOk() {
def service = mockFor(ApplicationService)
def myModel = new MyModel();
service.demand.getModel {
return myModel
}
controller.service = service.createMock()
def model = controller.index()
assertEquals myModel, model.myModel
assertEquals HttpServletResponse.SC_OK, response.status
}
这是一个例外:
org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method <init>() to invoke from this list:
public grails.test.MvcUnitTestCase#<init>(java.lang.String)
public grails.test.MvcUnitTestCase#<init>(java.lang.Class)
org.codehaus.groovy.runtime.metaclass.MethodSelectionException:无法从该列表中找到要调用的方法():
public grails.test.MvcUnitTestCase#(java.lang.String)
public grails.test.MvcUnitTestCase#(java.lang.Class)
MvcUnitTestCase
有两个构造函数,一个接受字符串,另一个接受类。我假设这与此有关,但我不确定为什么会发生这种情况。简单地使用mvcunitestcase
作为mixin的测试用例会导致这个问题。我认为问题可能在于,通过包含@TestMixin(mvcunitestcase)
您将两件事情混为一谈。您不需要这样做,因为您已经有了@TestFor(ApplicationController)
,它将自动混合到适当的东西中。