【发布时间】:2013-02-19 21:44:46
【问题描述】:
我在 then 子句中有一个循环测试:
result.each {
it.name.contains("foo")
it.entity.subEntity == "bar"
}
for (String obj : result2) {
obj.name.contains("foo")
obj.entity.subEntity == "bar"
}
最近我意识到循环没有经过真正的测试。无论我是否有 foo 或 bar 或其他任何东西,测试始终是绿色的 :) 我发现,必须以不同方式测试循环,例如与“每一个”?但只是将 'each' 更改为 'every' 会引发异常:
result.every {
it.name.contains("foo")
it.entity.subEntity == "bar"
}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Spec expression: 1: expecting '}', found '==' @ line 1, column 61.
s("foo") it.entity.rootEntity == "bar" }
我应该如何在测试中正确使用循环?我正在使用 spock 0.7-groovy-2.0
【问题讨论】:
标签: testing loops spock clause