Hi I have a scenario where I need to test whether a search service is bringing back the correct results. So my story looks something like this:
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 |
The table under the "Then" section would go on for a while, using different permutations of firstname/lastname criteria followed by nested tables of expected results in the results column. The Examples section would contain a list of possible search criteria passed to the "When" section
Is it possible to have nested tables like this? If not, is there perhaps another method I could use to accomplish the same thing?
I wound up re-writing my story as such:
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
I have one @When
annotated method for the When and And sentences in the story. The method accepts a firstName, lastName and ExamplesTable parameters using the matcher: "the first name is $firstnamecriteria and the last name is $lastnamecriteria the results should be: $resultsTable"
What I do is I throw the results table into a HashMap key'd by firstName/lastName, I then execute my search function on my service with those same firstName/lastName parameters and throw the results from the service call into another HashMap. In my @Then
method, I compare the two HashMap results to see if the expected results from the story match the actual results obtained by the service.
Seems to work ok, and is pretty readable.