2016-09-29 34 views
-1

当前正在实施GEB,Spock和Groovy。我碰到类似如何搜索并返回值并将其传递给spock表中的方法

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

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

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

} 
     } 

如果你提供了代码,这将是很大的帮助学习和imeplement。

回答

0

您不需要自己搜索表格或选择该数据。斯波克会做自动为您

期待:块只写一个使用模块的User_NamePass_word单元测试。 Spock会自动运行测试3次(与表格的行数一样多),依次将每行传递给您的测试。

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

我建议你多读一下关于数据驱动测试的Spock文档。

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

    } 
} 

什么斯波克会做的是运行测试一次从“里”块在数据表中的每一行,路过模块时,USER_NAME,Pass_Word作为参数,并断言在“期待”块您的期望。

请参阅Spock Data Driven Testing文档了解更多详情。

+0

场景是:传递模块名称,它将在匹配的where块中进行搜索,应该捕获user_name和pass_word并返回到另一个方法/类的密码将被解密,并且userid和password会将它发送到另一个模块凭据。但是在代码中,它返回true或者通过。 –

+0

请根据以上情况纠正我下面的代码。类PasswordCollection延伸规格{ DEF “安全密码数据驱动”(字符串的关键字){ 期望: 如果(关键字==模块) 返回encryptPassPass_word 其中: 模块| User_Name |密码 –

相关问题