我如何搜索并返回值并将其传递给spock表中的方法 [英] How can I search and return the values and pass it to the method from spock table

查看:235
本文介绍了我如何搜索并返回值并将其传递给spock表中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在实施GEB,Spock,Groovy。我遇到了像



这样的场景spock表中有一组数据。我必须将modulename作为参数传递,从spock表中搜索,然后返回两个值用户标识和密码。下面的代码是骨架代码



我的问题是如何根据参数搜索模块名称?
如何返回两个数据?

  Class Password_Collection extends Specification {

defSecure搜索和数据驱动的密码(字符串模块名称){

期望:
//基于模块名搜索其中
//选择值并返回采集的数据


其中:
Module | User_Name | Pass_word
login_Pass | cqauthor1 | SGVsbG8gV29ybGQ =
AuthorPageTest_Pass | cqauthor2 | DOIaRTd35f3y4De =
PublisherPage_pass | cqaauthor3 | iFK95JKasdfdO5 ==

}
}

如果您提供代码会对学习和补充很有帮助。

解决方案

  class YourSpec扩展了规格{
def Data Driven(Module,User_Name,Pass_Word){
expect:
classUnderTest.getUserNameForModule(Module)== User_Name $ b $ class classUnderTest.getPasswordForModule(Module)== Pass_Word

其中:
Module | User_Name | Pass_word
login_Pass | cqauthor1 | SGVsbG8gV29ybGQ =
AuthorPageTest_Pass | cqauthor2 | DOIaRTd35f3y4De =
PublisherPage_pass | cqaauthor3 | iFK95JKasdfdO5 ==

}
}

Spock会做什么从where块的数据表中的每一行运行测试一次,传递Module,User_Name,Pass_Word作为参数,并在expect块中声明您的期望值。



有关更多详细信息,请参阅 Spock数据驱动测试文档。


Currently implementing GEB,Spock,Groovy. I come across the scenario like

There is a set of data's in the spock table. I have to pass the modulename as a parameter, Search from the spock table then return two values user id and password. Below code is skeleton code

My question is how to search module name based on parameter? How to return two data's ?

Class Password_Collection extends Specification {

def "Secure password for search and Data Driven"(String ModuleName) {

   expect:
           // Search based on modulename in where
           // pick the values and return the picked data


            where:
            Module              | User_Name     | Pass_word
            login_Pass          | cqauthor1     | SGVsbG8gV29ybGQ =
            AuthorPageTest_Pass | cqauthor2     | DOIaRTd35f3y4De =
            PublisherPage_pass  | cqaauthor3    | iFK95JKasdfdO5 ==

}
        }

If you provide the code it would be great help to learn and imeplement.

解决方案

class YourSpec extends Specification {
    def "Secure password for search and Data Driven"(Module, User_Name, Pass_Word) {
        expect:
        classUnderTest.getUserNameForModule(Module) == User_Name
        classUnderTest.getPasswordForModule(Module) == Pass_Word

        where:
        Module              | User_Name     | Pass_word
        login_Pass          | cqauthor1     | SGVsbG8gV29ybGQ =
        AuthorPageTest_Pass | cqauthor2     | DOIaRTd35f3y4De =
        PublisherPage_pass  | cqaauthor3    | iFK95JKasdfdO5 ==

    }
}

What Spock will do is run your test one time for each row in the data table from the "where" block, passing Module, User_Name, Pass_Word as parameters and assert your expectations in the "expect" block.

Please refer to Spock Data Driven Testing documentation for more details.

这篇关于我如何搜索并返回值并将其传递给spock表中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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