Single column Date table issue:Groovy:Date variable '_' needs to be declared as method parameter
Asked Answered
R

2

15

I have a very simple test as blow:

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

According to the document http://spock-framework.readthedocs.org/en/latest/data_driven_testing.html Data tables must have at least two columns. A single-column table can be written as:

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

And I follow this rule,but got an error look like picture shown:

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

enter image description here

so,please tell me What the problem is here?

Raze answered 8/9, 2014 at 14:55 Comment(0)
K
5

The parameter list has to be either () or (Status editStatus, _). (You can't declare just one data variable but not the other.) There is an open pull request to allow (Status editStatus) in this particular case.

Krebs answered 8/9, 2014 at 15:9 Comment(1)
In recent snapshots, (Status editStatus) is supported.Krebs
M
18

Another way to achieve single column is to use data pipes http://spockframework.org/spock/docs/1.0/data_driven_testing.html

where:
editStatus << [FINISHED, CANCELED]
Monsignor answered 14/2, 2019 at 13:19 Comment(0)
K
5

The parameter list has to be either () or (Status editStatus, _). (You can't declare just one data variable but not the other.) There is an open pull request to allow (Status editStatus) in this particular case.

Krebs answered 8/9, 2014 at 15:9 Comment(1)
In recent snapshots, (Status editStatus) is supported.Krebs

© 2022 - 2024 — McMap. All rights reserved.