Until now, we have run Cucumber tests either from Eclipse or from a Terminal, but how can we use automation frameworks to work with Cucumber?
How do we integrate Cucumber with JUnit Framework? Let's take a look at this in the next section.
We need to create a Java class in the CucumberOptions
package with an empty body and the @RunWith
annotation. This is how the class should look like:
package com.CucumberOptions; import org.junit.runner.RunWith; import Cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) public class RunCukeTest { }
Cucumber ships with a JUnit runner, Cucumber.api.junit.Cucumber
. This class tells JUnit to invoke Cucumber JUnit runner
. It will search for Feature files and run them, providing the output back to JUnit in a format that it understands. Executing this class as any JUnit test class will run all the Features found on the classpath in the same package as this class.