2016-09-29 61 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 |密碼 –

相關問題