Mike Sallese Mike Sallese - 2 months ago 17
Groovy Question

How can I add information from my where clause to my test failure in Spock?

If I have the following spock test:

def "A should be smaller than B"() {
expect: "A is smaller than B"
A < B

where: "A and B take on the following values"
A|B|Path
5|6|/home
6|7|/home
7|5|/home/user


I expect the third where case to fail because 7 is not less than 5. The test failure in the html report is informative enough to show what the values of A and B are but I also want to know what the path was when looking at the report. How can I get the test report to include information about the path when this test fails?

Answer

You can do:

@Unroll
def "#A should be smaller than #B with #Path"() {
    expect: "A is smaller than B"
    A < B

    where: "A and B take on the following values"
    A|B|Path
    5|6|/home
    6|7|/home
    7|5|/home/user
}