编辑: 我无法再重现此问题。根本原因对我来说仍然是一个谜。
在一个带有2个单元测试的非常小的示例项目上运行grails test-app时,测试都是PASS,但之后我收到一条错误消息:
grails> test-app
| Running without daemon...
...............................................
|Compiling 1 source files
.
|Running 2 unit tests...
|Running 2 unit tests... 1 of 2
|Running 2 unit tests... 2 of 2
|Completed 2 unit tests, 0 failed in 0m 7s
.................
|Tests PASSED - view reports in C:\src\grails238-test\target\test-reports
Picked up _JAVA_OPTIONS: -Duser.home=C:\Users\rmorrise -Xms128M -Xmx512M -XX:PermSize=128M -XX:MaxPe
rmSize=384M
| Error Error running script test-app: org.codehaus.groovy.grails.cli.ScriptExitException (Use --sta
cktrace to see the full trace)
如果我的代码中出现错误,是否有人可以给我一些要查找的内容?
- stacktrace输出和测试规范代码如下。
| Error Error running script test-app --stacktrace: org.codehaus.groovy.grails.cli.ScriptExitExcepti
on (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
org.codehaus.groovy.grails.cli.ScriptExitException
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:98)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(
GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(
GantBinding.groovy)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBindin
g.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBindin
g.groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at TestApp$_run_closure1.doCall(TestApp.groovy:32)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(
GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(
GantBinding.groovy)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBindin
g.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBindin
g.groovy)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners$2.callCurrent(Unknown Source)
at gant.Gant$this$2$withBuildListeners$2.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:591)
at gant.Gant.executeTargets(Gant.groovy:590)
| Error Error running script test-app --stacktrace: org.codehaus.groovy.grails.cli.ScriptExitExcepti
on
以下是我的两个测试规范:
BookSpec:
package grails238.test
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(Book)
class BookSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test foo"() {
when:
domain.title = "Foo"
then:
domain.title == "Foo"
}
}
BookControllerSpec:
package grails238.test
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/
@TestFor(BookController)
class BookControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test foo"() {
when: "index"
controller.index()
then: "expect nothing"
controller.response.contentAsString == "Hello World"
}
}
答案 0 :(得分:3)
在Windows上使用grails 2.3.5和2.3.8,可以通过编辑" scripts / _GrailsTest.groovy"来修复。
第97行:
if(exitCode != null) {
应替换为
if(exitCode != null && exitCode != 0) {
答案 1 :(得分:0)
如果您删除了为脚本生成的测试文件,也可能。在test / cli /
下生成