Groovy 如何从spock表中搜索并返回值并将其传递给方法

Groovy 如何从spock表中搜索并返回值并将其传递给方法,groovy,spock,geb,Groovy,Spock,Geb,目前正在实现GEB、Spock和Groovy。我遇到这样的情况 spock表中有一组数据。我必须将modulename作为参数传递,从spock表中搜索,然后返回两个值user id和password。下面的代码是框架代码 我的问题是如何根据参数搜索模块名称? 如何返回两个数据 Class Password_Collection extends Specification { def "Secure password for search and Data Driven"(String Mod

目前正在实现GEB、Spock和Groovy。我遇到这样的情况

spock表中有一组数据。我必须将modulename作为参数传递,从spock表中搜索,然后返回两个值user id和password。下面的代码是框架代码

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

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 ==

}
        }

如果你提供了代码,学习和实现它将是非常有帮助的

您不需要自己搜索表或选择数据。斯波克会自动帮你做的

在expect:块中,只需编写使用模块、用户名和Pass单词的单元测试。Spock将自动运行测试3次(相当于表中的行数),将每一行依次传递给您的测试

从测试方法中删除参数ModuleName。这是不必要的

我建议您多阅读一点关于数据驱动测试的Spock文档

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 ==

    }
}
Spock将要做的是从“where”块中为数据表中的每一行运行一次测试,传递模块、用户名、传递单词作为参数,并在“expect”块中断言您的期望


有关更多详细信息,请参阅文档。

场景是:传递模块名,匹配后将在where块中搜索,用户名和密码应被捕获并返回到另一个方法/类密码将被解密,用户名和密码将作为凭据发送到另一个模块。但在代码中它返回true或pass。请根据上述场景更正下面的代码。类PasswordCollection扩展了规范{def“数据驱动的安全密码”(字符串关键字){expect:if(关键字==Module)返回EncryptPassass_word其中:Module | User_Name | Pass_word