使用生成的集成测试(grails create-integration-test package.ServiceName)时,我无法在测试中使用注入的服务 - 在 grails 插件中。
它抛出了一个非常无用的 NullPointerException
然而,同样的过程——但在 grails 应用程序中使用(grails create-app)完全没有问题。
您可以通过以下方式复制它:
> grails create-plugin myServicePlugin
>grails test-app
//按预期通过
>grails create-service testing.DummyService
更改\myServicePlugin\test\unit\testing\DummyServiceSpec.groovy
更改
void "test something"() {
}
至
void "test something"() {
expect:
def x = true
}
>grails test-app
//通过
>grails create-integration-test testing.DummyService
更改\myServicePlugin\test\integration\testing\DummyServiceSpec.groovy
更改
void "test something"() {
}
至
void "test something"() {
expect:
def x = true
}
>grails test-app integration:
//按预期通过
到目前为止一切都很好。现在编辑DummyService
做一些事情errmm .. Dummy-ish
改变\myServicePlugin\grails-app\services\testing\DummyService.groovy
添加
def dummySpit(){
return true
}
后def serviceMethod(){}
现在将服务注入测试规范
改变\myServicePlugin\test\integration\testing\DummyServiceSpec.groovy
添加def dummyService
以下
class DummyServiceSpec extends Specification {
并将"test something"
方法体更改为:
expect:
assert dummyService.dummySpit()
这就是世界倒塌的地方。
>grails test-app integration:
|Loading Grails 2.3.5
|Configuring classpath
.
|Environment set to test
...............
|Compiling 1 source files
........
|Running without daemon...
.......................................
|Compiling 1 source files
.
|Running 1 integration test...
|Running 1 integration test... 1 of 1
Failure: |
test something(testing.DummyServiceSpec)
|
java.lang.NullPointerException
at testing.DummyServiceSpec.test something(DummyServiceSpec.groovy:22)
|Completed 1 integration test, 1 failed in 0m 0s
.Tests FAILED
|
- view reports in G:\workspace\myServicePlugin\target\test-reports
Error |
Forked Grails VM exited with error