Spock: How to use test data with @Stepwise
Asked Answered
P

2

0

I used @Stepwise for automation. 8 test methods are running sequentially to complete the process. One of the methods take parameter and I want to pass different parameters to the method.

But the problem is: The method takes first set of parameter, then parameters are processed AND instead of proceeding to the next method, the method takes next set of parameter.

The source looks like:

@Stepwise
class AOSearchPageTest extends GebReportingSpec
{
    def "first_method"()
    {
    }

    def "second_method"()
    {
        when:
        at particularPage
        then:
        process(area)
        process(coutntry)
        process(airport)
        process(dest_area)
        process(dest_coutntry)
        process(dest_airport)

        where:
        area << ["asia","europe"]
        country << ["japan","uk"]
        port << ["narita","london"]
        dest_area << ["asia","europe"]
        dest_country << ["korea","italy"]
        dest_port << ["seul","florence"]
    }

    def "third_method"()
    {
        //Some other processing
    }

The second method first populate with the "asia","japan","narita","asia","korea","seul"

and instead of executing "third_method"(), it takes second set of parameter europe,uk,london,europe,italy,florence.

How I can process each set of data so that all methods [defs] will be executed top to bottom for each set of data?

Pash answered 30/8, 2016 at 7:20 Comment(1)
What exactly are you testing? There are no assertions in your test.Crissycrist
P
1

First of all, @Stepwise

Indicates that a spec's feature methods should be run sequentially in their declared order (even in the presence of a parallel spec runner), always starting from the first method. If a method fails, the remaining methods will be skipped. Feature methods declared in super- and subspecs are not affected.

where clause indicates that how many times your method will be executed. You can't go from one method to another without finishing it's full execution. So, u can move your dependents tasks into one method and move some processing in your helper method to reduce line of code in your spec method.

Punchy answered 2/9, 2016 at 9:53 Comment(0)
M
0

Make your third_method a private standalone method that is not executed as a test, and invoke it after the processing block in the second_method. Something like this:

@Stepwise
class AOSearchPageTest extends GebReportingSpec
{
    def "first_method"()
    {
    }

    def "second_method"()
    {
        when:
        at particularPage

        then:
        process(area)
        process(coutntry)
        process(airport)
        process(dest_area)
        process(dest_coutntry)
        process(dest_airport)

        and:
        thirdMethod()

        where:
        area << ["asia","europe"]
        country << ["japan","uk"]
        port << ["narita","london"]
        dest_area << ["asia","europe"]
        dest_country << ["korea","italy"]
        dest_port << ["seul","florence"]
    }

    private def thirdMethod()
    {
        //Some other processing
    }

But be careful, in this case the thirdMethod needs to return a boolean result which indicates a success or a fail of what was previously your third_method test.

Marginalia answered 2/9, 2016 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.