JBehave中的嵌套表

时间:2012-03-07 15:42:45

标签: java bdd 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               |

“Then”部分下的表将持续一段时间,使用firstname / lastname标准的不同排列,然后是结果列中预期结果的嵌套表。 “示例”部分将包含传递给“何时”部分的可能搜索条件列表

是否可以拥有这样的嵌套表?如果没有,是否还有其他方法可以用来完成同样的事情?

2 个答案:

答案 0 :(得分:1)

根据我的理解不直接支持 - 尽管将ExampleTable值作为参数获取将引入ParameterConverters - 默认情况下设置了一个ExampleTable ParameterConverter。我确信那里有一个解析错误。

那就是说,你的“然后”需要适用于所有行的例子:部分。我敢肯定,这就是为什么你想把所有这些都放在那个 - 然后你可以选择正确的。

你能做到以下几点:

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     |

答案 1 :(得分: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和And语句有一个@When注释方法。该方法使用匹配器"the first name is $firstnamecriteria and the last name is $lastnamecriteria the results should be: $resultsTable"

接受firstName,lastName和ExamplesTable参数

我所做的是将结果表抛出到firstName / lastName的HashMap键中,然后我使用相同的firstName / lastName参数在我的服务上执行搜索功能,并将服务调用的结果抛出到另一个HashMap中。在我的@Then方法中,我比较了两个HashMap结果,看看故事的预期结果是否与服务获得的实际结果相符。

似乎工作正常,并且非常易读。