Spock: How to use test data with @Stepwise

我与影子孤独终老i 提交于 2019-12-25 04:21:04

问题


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?


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/39221187/spock-how-to-use-test-data-with-stepwise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!