我创建了一个 BaseController,我将它混入其他控制器。
例子:
class BaseController () {
def somemethod () {
return "some method"
}
}
@Mixin(BaseController)
class MyController {
def getsomething() {
def test = somemethod()
return test
}
}
我正在尝试编写一个测试用例,MyController
但是它失败了,因为它找不到somemethod
.
我的测试目前看起来像这样
@TestFor(MyController)
class MyControllerSpec extends Specification {
def "test getsomething" () {
when:
def m = controller.getsomething()
then:
response.contentAsString == "some method"
}
}
但我不断收到这样的错误:
No signature of method: somemethod() is applicable for argument types: () values: []
问题
我如何编写 spock 测试MyController
以便它也能somemethod
找到