Book Image

Cucumber Cookbook

By : Shankar Garg
Book Image

Cucumber Cookbook

By: Shankar Garg

Overview of this book

Table of Contents (13 chapters)
Cucumber Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

Note

The name of the JUnit class is irrelevant...