gpt4 book ai didi

grails - Grails 3.3.8:无法解析ControllerUnitTest

转载 作者:行者123 更新时间:2023-12-02 15:17:10 30 4
gpt4 key购买 nike

我正在尝试编写一些基本的 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com