单列日期表问题:Groovy:日期变量'_'需要声明为方法参数

问题描述 投票:7回答:2

我有一个非常简单的测试:

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         |_
}

根据文档http://spock-framework.readthedocs.org/en/latest/data_driven_testing.html数据表必须至少有两列。单列表可以写成:

where:
a | _
1 | _
7 | _
0 | _

我遵循这条规则,但得到的错误如下图所示:

Groovy:Date variable '_' needs to be declared as method parameter

所以,请告诉我这里的问题是什么?

spock data-driven-tests
2个回答
5
投票

参数列表必须是()(Status editStatus, _)。 (你不能只声明一个数据变量而不能声明另一个数据变量。)在这种特殊情况下,有一个允许(Status editStatus)的开放拉取请求。


1
投票

实现单列的另一种方法是使用数据管道http://spockframework.org/spock/docs/1.0/data_driven_testing.html

where:
editStatus << [FINISHED, CANCELED]
© www.soinside.com 2019 - 2024. All rights reserved.