Spock:如何重复运行一组方法作为单个测试? [英] Spock: How to run a set of methods as a single test repeatedly?

查看:245
本文介绍了Spock:如何重复运行一组方法作为单个测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的测试用例:

  def进入主页并点击登录按钮并进入登录页面
{
}

def输入用户名和密码并点击登录
{
时:
代码....
then:
code ....
其中:
param1<< [ID1,ID2,ID3]
param2<< [密码1,密码2,密码3]
}

测试包含两个defs。
我想用不同的ID和密码重复整个过程。
我该怎么做?



例如:

   - 首先执行def转到主页并点击登录按钮并进入登录页面

- 执行def输入用户名和密码并点击登录

我想循环使用所有的ID和密码。


我的原始代码在这里:

  @Stepwise 
class AOSearchPageTest extends GebReportingSpec
{
@Shared def orig_list = ['东京(成田·羽田)','日本','アジア']
@共享def dest_list = ['ソウル','韩国','アジア']
$ b $ defSelect origin()
{
当:单击国际单选按钮
打开主页()
单击oneWayRadioButton

然后:选择出发点
代码...

和:选择目的地点
代码...

和:
选择出发d ()
Click searchButton()
选择产品详情()
会员登录()
输入详细信息页面()

其中:
area |国家|端口| dest_area | dest_country | dest_port
'アジア'| '日本'| '东京(成田·羽田)' 'アジア'| '韩国'| 'ソウル'
'ヨーロッパ'| 'イギリス'| 'ロンドン'| 'ヨーロッパ'| 'イタリア'| 'フィレンツ'
}

私人开放主页()
{
与上述功能相同
}

私人点击oneWayRadioButton()
{
与上述功能相同
}

private选择出发日期()
{
when :点击搜索按钮
...
然后:点击登录按钮
...
}

私人点击searchButton( )
{
当:单击搜索按钮
...
然后:单击登录按钮
...
}

私人选择产品详情()
{
与上述功能相同
}

私人会员登录()
{
与上述函数相同
}

私有输入详细信息页面()
{
与上述函数相同
}

我有一个如下的测试用例:首页,点击登录按钮并进入登录页面
{
}

private输入用户名和密码并点击登录
{
}
$ b $ def整个测试的名称
{
when:
转到主页并单击登录按钮并转到登录页面()
输入用户ID和密码并点击登录()
然后:
代码....
其中:
param1<< [ID1,ID2,ID3]
param2<< [密码1,密码2,密码3]
}


I have a test case like below:

def "Go to home page and click login button and go to login page"
{
}

def "Input user ID and password and click login"
{
    when:
        code....
    then:
        code....
    where:
        param1 << [ID1,ID2,ID3]
        param2 << [password1,password2,password3]
}

The test consists of two defs. I want to repeat the whole process with different ID and Password. How I can do that?

For example:

- First execute def "Go to home page and click login button and go to login page"

- Than execute def "Input user ID and password and click login" 

I want to loop for all sets of ID and password.

EDITED: My Original code here:

@Stepwise
class AOSearchPageTest extends GebReportingSpec
{
@Shared def orig_list = ['東京(成田・羽田)', '日本','アジア' ]
@Shared def dest_list = ['ソウル', '韓国','アジア' ]

def "Select origin"()
{
    when: "Clicking international radio button"
        "Open Homepage"()
        "Click oneWayRadioButton"()

    then: "Select departure point"
        code ...

    and: "Select destination point"
        code...

    and:
        "Select departure date"()
        "Click searchButton"()
        "Select product details"()
        "Member login"()
        "Input detail page"()

    where:
        area | country | port | dest_area | dest_country | dest_port
        'アジア' | '日本'    | '東京(成田・羽田)' | 'アジア'     | '韓国'        | 'ソウル'
        'ヨーロッパ' | 'イギリス'    | 'ロンドン' | 'ヨーロッパ'     | 'イタリア'        | 'フィレンツェ'
}

private "Open Homepage"()
{
    same like above functions
}

private "Click oneWayRadioButton"()
{
    same like above functions
}

private "Select departure date"()
{
    when: "Clicking search button"
    ...
    then: "Click Login Button"
    ...
}

private "Click searchButton"()
{
    when: "Clicking search button"
    ...
    then: "Click Login Button"
    ...
}

private "Select product details"()
{   
    same like above functions
}

private "Member login"()
{
    same like above functions
}

private "Input detail page"()
{
    same like above functions
}   
}

解决方案

Every public method in Spock is considered as separate test. If you want to compose many methods in one test, they should be private. You need to redesign the thing, for example: I have a test case like below:

private "Go to home page and click login button and go to login page"
{
}

private "Input user ID and password and click login"
{
}

def "Name of the entire test"
{
    when:
        "Go to home page and click login button and go to login page"()
        "Input user ID and password and click login"()
    then:
        code....
    where:
        param1 << [ID1,ID2,ID3]
        param2 << [password1,password2,password3]
}

这篇关于Spock:如何重复运行一组方法作为单个测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆