Spock:如何通过@Stepwise使用测试数据 [英] Spock: How to use test data with @Stepwise
问题描述
我使用@Stepwise进行自动化.依次运行8种测试方法以完成该过程.其中一种方法采用参数,我想将不同的参数传递给该方法.
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.
但是问题是:该方法采用第一组参数,然后对参数进行 AND 处理,而不是继续进行下一个方法,该方法采用下一组参数.
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.
来源看起来像:
@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
}
第二种方法首先填充"asia","japan","narita","asia","korea","seul"
The second method first populate with the "asia","japan","narita","asia","korea","seul"
,而不是执行"third_method"(), 它需要第二组参数 欧洲,英国,伦敦,欧洲,意大利,佛罗伦萨.
and instead of executing "third_method"(), it takes second set of parameter europe,uk,london,europe,italy,florence.
如何处理每组数据,以便对每组数据从上至下执行所有方法[defs]?
How I can process each set of data so that all methods [defs] will be executed top to bottom for each set of data?
推荐答案
将您的third_method
设为不作为测试执行的私有独立方法,然后在second_method
中的处理块之后调用它.像这样:
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
}
但是要小心,在这种情况下,thirdMethod
需要返回一个布尔结果,该结果指示先前的third_method
测试成功还是失败.
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.
这篇关于Spock:如何通过@Stepwise使用测试数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!