emi*_*lan 2 grails integration-testing intellij-idea spock
我使用Grails 2.4.4作为我的应用程序.我为我的控制器写了一个集成测试.
class UserControllerIntegrationSpec extends IntegrationSpec {
UserController controller = new UserController()
void "test something"() {
when:
controller.request.method = 'POST'
controller.create()
then:
controller.response.status == HttpStatus.OK.value()
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用IntelliJ运行测试时,我得到一个例外:
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
Run Code Online (Sandbox Code Playgroud)
当我使用带test-app命令的控制台运行集成测试时没有问题.PS单元测试工作没有问题.
您不能像在单元测试中那样在IDE中单独运行集成测试.集成测试环境的运行时间几乎和运行时一样多run-app,其中一个很大的区别就是没有Web服务器.
所以测试基础架构期望有一个Spring Application上下文(至少部分因此依赖注入将适用于测试类),GORM,插件等.所以你可以从IDE运行集成测试,但是他们必须运行grails test-app和捕获输出,就像在IDE中运行应用程序一样.
| 归档时间: |
|
| 查看次数: |
2253 次 |
| 最近记录: |