2012-03-07 91 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