Running tests with Maven
As we already have Maven set up to use for managing our project and dependencies, we will use it next to run the tests. This will be crucial for later when we want to set up Karate test runs within build pipelines. The most straightforward way to do this is to write one or more runner classes that Maven can execute. In this section, we will look at the runners that are already included in our generated Maven archetype example project.
Understanding Karate runners
In our project, we can see two different files that are examples of how to run tests:
ExampleTests.java
in theexamples
directoryUsersRunner.java
right next tousers.feature
inside ofexamples/users
Figure 4.16 – Included runners in Karate’s example project
Runners are needed when tests should be run from Maven, more specifically Maven Surefire. This is the default Maven plugin for executing Java unit tests.
Looking at the pom.xml...