For general information about data tables please refer to the polyglot project for specific information the DataTable javadoc.
The matchers module contains Hamcrest matchers to compare data tables. These can be used in most common test frameworks and produces pretty error messages.
Add the datatable-matchers
dependency to your pom.
<dependencies>
[...]
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable-matchers</artifactId>
<version>${cucumber-datatable.version}</version>
<scope>test</scope>
</dependency>
[...]
</dependencies>
Use the matcher in your step definition.
import static io.cucumber.datatable.matchers.DataTableHasTheSameRowsAs.hasTheSameRowsAs;
[...]
private final DataTable expected = DataTable.create(
asList(
asList("Annie M. G.", "Schmidt"),
asList("Roald", "Dahl"),
));
@Then("these authors have registered:")
public void these_authors_have_registered(DataTable registeredAuthors){
assertThat(registeredAuthors, hasTheSameRowsAs(expected).inOrder());
// java.lang.AssertionError:
// Expected: a datable with the same rows
// but: the tables were different
// - | Annie M. G. | Schmidt |
// | Roald | Dahl |
// + | Astrid | Lindgren |
}
Not building?
We're using shaded dependencies in a reactor build so make sure you run mvn clean install
the first time.
IntelliJ IDEA also doesn't know how to handle the shaded pom
mvn install
- Open the 'Maven Projects' tool window.
- Choose "Shaded DataTable Dependencies" -> "Ignore Projects".
- Open Project Structure, choose the "DataTable" module, add jars, select dependencies/datatable-dependencies-....jar
- Select the top level
pom.xml
and choose "Maven" -> "Reimport".