The JUnit way

Maven can intelligently find any JUnit test in your source code and run the same.

You just need to run a single command from inside your project directory.

mvn test

In our case, it should find the RunFeatures class and trigger the tests as configured in the CucumberOptions annotation.

But it won't. Here is the catch.

Maven expects the Junit test class to end with the word test. So we need to rename the RunFeatures class to something that end with a 'Test' word. Let's name it RunCukesTest.

So now it should look like the following:

@RunWith(Cucumber.class)
@CucumberOptions (features = "src/test/java/features/")
public class RunCukesTest {
}

If we now run the 'mvn test' command from commandline, it will run all the feature tests.

Further, CucumberOptions only talks about what features to run. Let's add some formatting options for the results of the test run.

Cucumber gives you a couple of options for result formatting.

  • HTML
  • Json

We will add both for our tests.

Consider the following code for result formatting.

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/java/features/",
        format = {"pretty", "html:target/cucumber", "json:target/cucumber-report.json"})
public class RunCukesTest {
}

Running the same tests would now produce an html result and also a json output. You can see the same in the target folder inside your project.

results matching ""

    No results matching ""