我正在尝试编写一些基本的控制器测试,并且正在遵循文档https://docs.grails.org/latest/guide/testing.html。我的测试当前无法找到 ControllerUnitTest 。我缺少依赖项吗?
这是我的进口
grails.testing.web.controllers.ControllerUnitTest
答案 0 :(得分:1)
package mcroteaucontrollertest
import grails.testing.web.controllers.ControllerUnitTest
import spock.lang.Specification
import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED
class DemoControllerSpec extends Specification implements ControllerUnitTest<DemoController> {
void "test GET request"() {
when:
controller.index()
then:
response.text == 'Success'
}
void "test POST request"() {
when:
request.method = 'POST'
controller.index()
then:
response.status == METHOD_NOT_ALLOWED.value()
}
}
ControllerUnitTest
特性由grails-web-testing-support
提供。确保您有testCompile "org.grails:grails-web-testing-support"
之类的内容,如{{3}}所示。