Follow my blog with Bloglovin

Sunday, December 29, 2013

Play Behavior Driven Development with Cucumber

Cucumber is an behavior driven testing framework. In this post I will describe how to use this Play application.

To use Cucumber we need to install (add dependency to Play) four Cucumber modules :

  • cucumber-core Core Cucumber module
  • cucumberjava Cucumber Java language module.
  • cucumber-spring Cucumber Spring module for dependency injection of test related classes. Will not use this in this tutorial.
  • cucumber-junit Cucumer JUnit runner to run tests.
Add following dependencies in /project/Build.scala :

  val appDependencies = Seq(
    // Add your project dependencies here
    "info.cukes" % "cucumber-jvm" % "1.1.5",
    "info.cukes" % "cucumber-java" % "1.1.5",
    "info.cukes" % "cucumber-spring" % "1.1.5",
    "info.cukes" % "cucumber-junit" % "1.1.5"

Note: If editing in Eclipse or other IDE the classpath maintained by IDE will not update with Spring dependency added. For this, run "play eclipse" (or corresponding IDE) command from Play console and then import project in IDE.

Create a class in /test folder of Play application:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@CucumberOptions(format = "pretty")
public class CucumberTest {


This empty class will launch Cucumber tests.

Write step definition (behaviors) as described here.

Popular Posts