Ale*_*uya 7 data-driven-tests spock
我有一个非常简单的测试:
def "setContent_activity_finished"(Status editStatus) {
// Variables.........................
given:
activity.getStatus() >> editStatus.toString()
when:
handler.setContent(activityId,jsonString)
then:
0*view.appendPossible(_)
where:
editStatus |_
FINISHED |_
CANCELED |_
}
Run Code Online (Sandbox Code Playgroud)
根据文档http://spock-framework.readthedocs.org/en/latest/data_driven_testing.html 数据表必须至少有两列.单列表可以写成:
where:
a | _
1 | _
7 | _
0 | _
Run Code Online (Sandbox Code Playgroud)
我遵循这条规则,但得到的错误如下图所示:
Groovy:Date variable '_' needs to be declared as method parameter
Run Code Online (Sandbox Code Playgroud)

所以,请告诉我这里的问题是什么?
Yan*_*ski 11
实现单列的另一种方法是使用数据管道 http://spockframework.org/spock/docs/1.0/data_driven_testing.html
where:
editStatus << [FINISHED, CANCELED]
Run Code Online (Sandbox Code Playgroud)
参数列表必须是()或(Status editStatus, _).(您不能只声明一个数据变量而不能声明另一个数据变量.)(Status editStatus)在这种特殊情况下,有一个允许打开的拉取请求.