Since Concordion 2.0.0
The BestMatch strategy can be applied to the verify rows command to find the best matching row in the specification for each item in the collection returned by the fixture.
The strategy is applied by adding the
concordion:matchStrategy="BestMatch"
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 best match algorithm is:
Each of the following scenarios uses the command:
<table concordion:verifyRows="#user : users" concordion:matchStrategy="BestMatch"> <tr> <th concordion:assertEquals="#user.firstName">First Name</th> <th concordion:assertEquals="#user.lastName">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 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> |
||
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, each with different 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,Smither,17}; {Jane,Dou,17} |
<tr> <td class="success">John</td> <td class="failure"><del class="expected">Smith</del> <ins class="actual">Smither</ins></td> <td class="success">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">17</ins></td> </tr> |
||
Two rows, each with different incorrect field, order is different | <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,Smither,17} |
<tr> <td class="success">John</td> <td class="failure"><del class="expected">Smith</del> <ins class="actual">Smither</ins></td> <td class="success">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">17</ins></td> </tr> |
||
Two rows, first with two incorrect fields, second with one, order is different | <tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> <tr> <td>Jane</td> <td>Dou</td> <td>22</td> </tr> |
{Jane,Dou,18}; {John,Smither,23} |
<tr> <td class="success">John</td> <td class="failure"><del class="expected">Smith</del> <ins class="actual">Smither</ins></td> <td class="failure"><del class="expected">17</del> <ins class="actual">23</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">18</ins></td> </tr> |
||
First row is surplus, second one with incorrect field | <tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{Jane,Smith,18}; {John,Smith,23} |
<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">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">18</ins></td></tr> |
||
Expected one row, got two, each with one field different. Report both surplus as matching ambiguous |
<tr> <td>John</td> <td>Smith</td> <td>17</td> </tr> |
{John,Smith,18}; {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">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">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> |