Since Concordion 2.0.0
The KeyMatch strategy can be applied to the verify rows command to find a matching row, prior to verifying the contents of the row. The match is performed against a subset of the table columns, defined by marking those columns as key fields.
The strategy is applied by adding the concordion:matchStrategy="KeyMatch"
attribute to the verify rows command.
Please note that the commands on the table header are being evaluated on a copy of the rows multiple times. This means the commands have to be idempotent and lightweight.
The strategy is:
The key match algorithm is:
Each of the following scenarios uses the command:
<table concordion:verifyRows="#user : users" concordion:matchStrategy="KeyMatch"> <tr> <th concordion:assertEquals="#user.firstName" concordion:matchingRole="key">First Name</th> <th concordion:assertEquals="#user.lastName" concordion:matchingRole="key">Last Name</th> <th concordion:assertEquals="#user.age">Age</th> </tr> [ROWS] </table>
with [ROWS] replaced by the Expected [ROWS] and Result [ROWS].
Scenario | Expected [ROWS] | Expected Table | Actual | Result [ROWS] | Result Table |
---|---|---|---|---|---|
All match in same order |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{John,Smith,17}; {Jane,Dou,22} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="success">22</td> </tr> |
||
All match in different order |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{Jane,Dou,22}; {John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="success">22</td> </tr> |
||
All match in different order with duplicates |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{Jane,Dou,22}; {John,Smith,17}; {Jane,Dou,22} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="success">22</td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="success">22</td> </tr> |
||
One row missing |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr class="missing"> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
||
One surplus row |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{Jane,Dou,22}; {John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">Jane</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Dou</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">22</ins></td></tr> |
||
One of the duplicated rows missing |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr class="missing"> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
||
One surplus duplicate |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,17}; {John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="success">17</td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">John</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Smith</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">17</ins></td></tr> |
||
One non key field is incorrect |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,22} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="failure"><del class="expected">17</del> <ins class="actual">22</ins></td> </tr> |
||
One key field is incorrect |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{Jane,Smith,17} |
<tr class="missing"> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">Jane</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Smith</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">17</ins></td></tr> |
||
Two rows, each with incorrect field |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{John,Smith,22}; {Jane,Dou,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="failure"><del class="expected">17</del> <ins class="actual">22</ins></td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="failure"><del class="expected">22</del> <ins class="actual">17</ins></td> </tr> |
||
Two rows in different order, each with incorrect field |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{Jane,Dou,17}; {John,Smith,22} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="failure"><del class="expected">17</del> <ins class="actual">22</ins></td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="failure"><del class="expected">22</del> <ins class="actual">17</ins></td> </tr> |
||
Two rows, first with incorrect key, second with incorrect value |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{John,Smither,17}; {Jane,Dou,18} |
<tr class="missing"> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td class="success">Jane</td> <td class="success">Dou</td> <td class="failure"><del class="expected">22</del> <ins class="actual">18</ins></td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">John</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Smither</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">17</ins></td></tr> |
||
Duplicated key in actual data |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,23}; {John,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="failure"><del class="expected">17</del> <ins class="actual">23</ins></td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">John</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Smith</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">17</ins></td></tr> |
||
Expected one row, got two, each with one field different. Find matching by key. |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,18}; {Jane,Smith,17} |
<tr> <td class="success">John</td> <td class="success">Smith</td> <td class="failure"><del class="expected">17</del> <ins class="actual">18</ins></td> </tr> <tr class="surplus"><td class="failure"><del class="expected"> </del> <ins class="actual">Jane</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">Smith</ins></td><td class="failure"><del class="expected"> </del> <ins class="actual">17</ins></td></tr> |