我已将单元测试编写为extend
grails' GrailsUnitTestCase
。我使用Spock框架编写了新的单元测试。使用以下命令运行单个Spock Spec
就可以了。
prayag@prayag:~/gccount$ grails test-app spock: ChronicSpec
但是运行现有的UnitTests会在Spock测试中抛出编译错误。
prayag@prayag:~/gccount$ grails test-app unit: ChronicUnitTest.testDefaultChronic
| Error Compilation error compiling [unit] tests: startup failed:
/home/prayag/gccount/test/unit/com/zazzercode/chronic/ChronicSpec.groovy: 45: unexpected token: } @ line 45, column 5.
} //end of response process
^
1 error
ChronicSpec.groovy
如下所示
class ChronicSpec extends Specification {
final public String CHRONIC_DEFAULT_METRIC = ReportType.CHRONIC_REPORT + Constants.COLON + ChronicMetrics.DEFAULT
final public String INDEX_NAME = "gccount"
ChronicService chronicService
void "when response is processed json should be created"() {
given:
def contentBuilder = XContentFactory.jsonBuilder().startObject()
chronicService = new ChronicService()
//other code goes here
when:
listener.writeJson(records, contentBuilder, "chronic")
then:
//assertion goes here
} //end of response process => this is where exception is thrown
}
工具使用
grails:2.2.3
spock:0.7答案 0 :(得分:1)
我很惊讶这实际上是编译,你不能留空“then:”阻止。
您至少需要一个断言。正如塞尔吉奥·米歇尔斯所建议的,添加一个断言,它应该修复它。