Integrating Cucumber with JUnit

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.

How to do it…

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 {
}

How it works…

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 ...

Get Cucumber Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.