2012-03-07 88 views
0

嗨我有一個場景,我需要測試一個搜索服務是否正在帶回正確的結果。所以,我的故事看起來是這樣的:JBehave中的嵌套表格

Narrative: 
In order to easily discover if a player is registered in a loyalty program 
As a customer service representative 
I want to be able to search for registered players by player first and last name 

Scenario: Retrieve Player information by First and Last Name 

Given players registered in the Data Warehouse and some combination of Loyalty1 and/or Loyalty2 programs: 
|first name|last name|city  |province|loyalty1 |loyalty2| 
|Pete  |Walter |Winnipeg |<null> |false |true | 
|Jon  |Dewit |Winnipeg |MB  |true  |true | 
|John  |Dewit |<null> |<null> |true  |true | 
|Peter  |Dewalt |<null> |<null> |true  |false | 

When the <firstnamecriteria> and <lastnamecriteria> criteria are specified 

Then the system displays the correct results, using a case-insensitive "begins with" search as follows: 
|firstnamecriteria|lastnamecriteria|results    | 
|Jo    |    ||first name|last name|| 
|     |    ||Jon  |Dewit || 
|     |    ||John  |Dewit || 

Examples: 
|firstnamecriteria|lastnamecriteria| 
|Jo    |    | 
|     |Dew    | 
|J    |D    | 

在桌子底下「然後」節會去一會兒,使用的名字/姓氏標準,然後在結果列預期結果的表格嵌套不同的排列。 Examples部分將包含傳遞給「When」部分的可能搜索條件列表

是否有可能具有這樣的嵌套表格?如果不是,那麼我可以用另一種方法來完成同樣的事情嗎?

回答

0

彼時我重新寫我的故事,因爲這樣的:

Given players registered in the Data Warehouse and some combination of Loyalty1 and/or Loyalty2 : 
|first name|last name|city  |province|loyalty1 |loyalty2| 
|Pete  |Walter |Winnipeg |<null> |false |true | 
|Jon  |Dewit |Winnipeg |MB  |true  |true | 
|John  |Dewit |<null> |<null> |true  |true | 
|Peter  |Dewalt |<null> |<null> |true  |false | 

When the first name is Jon and the last name is Dewit the results should be: 
|first name|last name| 
|Jon  |Dewit | 

And the first name is <null> and the last name is dewit the results should be: 
|first name|last name| 
|Jon  |Dewit | 
|John  |Dewit | 

And the first name is <null> and the last name is de the results should be: 
|first name|last name| 
|Jon  |Dewit | 
|John  |Dewit | 
|Peter  |Dewalt | 

Then the system displays the correct results, using a case-insensitive "begins with" search 

我對何時和句子中的故事一個@When註解的方法。該方法接受使用匹配器的firstName,lastName和ExamplesTable參數:"the first name is $firstnamecriteria and the last name is $lastnamecriteria the results should be: $resultsTable"

我所做的是我把結果表放入由firstName/lastName鍵入的HashMap中,然後在服務上執行我的搜索功能相同的firstName/lastName參數並將服務調用的結果引入另一個HashMap。在我的@Then方法中,我比較了兩個HashMap結果,以查看故事的預期結果是否與服務獲得的實際結果相匹配。

似乎工作正常,而且非常可讀。

1

根據我的理解,直接不支持這種方法 - 儘管將ExampleTable的值作爲參數將會在ParameterConverters中啓動 - 默認情況下會設置一個ExampleTable ParameterConverter。我確定那裏有一個解析錯誤。

也就是說,您的「Then」需要適用於示例的所有行:部分。我確信這就是爲什麼你想把所有人都放在那裏 - 然後你可以挑出合適的人。

你能做到以下幾點:

Given players registered in the Data Warehouse and some combination of Loyalty1 and/or Loyalty2 programs: 
|id|first name|last name|city  |province|loyalty1 |loyalty2| 
|1 |Pete  |Walter |Winnipeg |<null> |false |true | 
|2 |Jon  |Dewit |Winnipeg |MB  |true  |true | 
|3 |John  |Dewit |<null> |<null> |true  |true | 
|4 |Peter  |Dewalt |<null> |<null> |true  |false | 
When the <firstnamecriteria> and <lastnamecriteria> criteria are specified 
Then the system displays the correct results, using a case-insensitive "begins with" search with users <userlist> 

Examples: 
|firstnamecriteria|lastnamecriteria|userlist| 
|Jo    |    |2,3  | 
|     |Dew    |2,3,4 | 
|J    |D    |2,3  | 
+0

或指定一個字符串指向一個資源,你可以得到和驗證(通過網址而不是內聯表) – 2012-03-07 20:29:51

+0

這是我也曾想到的解決方案,但問題是我在這個集成測試中的底層數據庫選擇我的id值,所以我不知道他們是什麼時間的頭。話雖如此,我可以像你所說的那樣使它工作,爲此+1 – ThaDon 2012-03-08 20:19:13