作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一些基本的 Controller 测试,并且正在遵循文档https://docs.grails.org/latest/guide/testing.html。我的测试当前无法找到 ControllerUnitTest 。我是否缺少依赖项?
这是我的进口
grails.testing.web.controllers.ControllerUnitTest
最佳答案
请参阅https://github.com/jeffbrown/mcroteaucontrollertest上的项目。
https://github.com/jeffbrown/mcroteaucontrollertest/blob/master/src/test/groovy/mcroteaucontrollertest/DemoControllerSpec.groovy
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"
的内容,如
https://github.com/jeffbrown/mcroteaucontrollertest/blob/cf5f09b1c2efaba759f6513301d7b55fcb29979b/build.gradle#L56所示。
关于grails - Grails 3.3.8:无法解析ControllerUnitTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53771682/
我是一名优秀的程序员,十分优秀!