sbt/sbt-cucumber

Name: sbt-cucumber

Owner: sbt

Description: Cucumber plugin for SBT.

Created: 2017-11-04 18:55:27.0

Updated: 2018-01-26 12:25:48.0

Pushed: 2017-11-10 13:54:56.0

Homepage: null

Size: 28

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SBT Cucumber

The Cucumber plugin provides a new sbt command, allowing you to run just your Cucumber tests using sbt cucumber.

The plugin can be used if you want a separate command to run Cucumber tests and have your normal test framework ignore Cucumber tests. If you want to run Cucumber tests within a ScalaTest unit test framework see here.

Dependency Information
SbtPlugin("com.waioeka.sbt" % "cucumber-plugin" % "0.1.7")

Note, the latest version of the plugin is built using SBT 1.0.2.

Cucumber Plugin Example

The project cucumber-plugin-example highlights how to use the plugin. You will need to ensure that your build.sbt file defines both the dependencies and the 'glue' setting (i.e. where to find the step definitions).

name := "cucumber-test"

organization := "com.waioeka.sbt"

version := "0.1.0"

libraryDependencies ++= Seq (
"io.cucumber" % "cucumber-core" % "2.0.1" % "test",
"io.cucumber" %% "cucumber-scala" % "2.0.1" % "test",
"io.cucumber" % "cucumber-jvm" % "2.0.1" % "test",
"io.cucumber" % "cucumber-junit" % "2.0.1" % "test",
"org.scalatest" %% "scalatest" % "2.2.5" % "test")

enablePlugins(CucumberPlugin)

CucumberPlugin.glue := "com/waioeka/sbt/"

// Any environment properties you want to override/set.
CucumberPlugin.envProperties := Map("K"->"2049")

Remember to set the CucumberPlugin.glue parameter to the sub directory in test that contains your Scala step definitions. In your resources directory, put in your feature files.

@my-tag
Feature: Multiplication
  In order to avoid making mistakes
  As a dummy
  I want to multiply numbers

Scenario: Multiply two variables
Given a variable x with value 2
And a variable y with value 3
When I multiply x * y
Then I get 6

If you need to generate the stubs, just run sbt cucumber and you will get an error complaining about missing stubs. You can copy and paste the stub functions into your step implementation.

You can now put in your stub implementation:

package com.waioeka.sbt

import cucumber.api.scala.{ScalaDsl, EN}
import org.scalatest.Matchers

/** AddAndMultiplySteps*/
class MultiplicationSteps extends ScalaDsl with EN with Matchers {
  var x : Int = 0
  var y : Int = 0
  var z : Int = 0

  Given("""^a variable x with value (\d+)$""") { (arg0: Int) => x = arg0 }

  Given("""^a variable y with value (\d+)$""") { (arg0: Int) => y = arg0 }

  When("""^I multiply x \* y$""") { () => z = x * y }

  Then("""^I get (\d+)$""") { (arg0: Int) => z should be (arg0) }
}

To run the tests in standalone mode:

compile
cucumber

You should see some output as follows:

oa:cucumber-test lewismj$ sbt cucumber
o] Loading project definition from /Users/lewismj/waioeka/upa-plugins/cucumber-test/project
o] Set current project to cucumber-test (in build file:/Users/lewismj/waioeka/upa-plugins/cucumber-test/)
o] Feature: Multiplication
o]   In order to avoid making mistakes
o]   As a dummy
o]   I want to multiply numbers
o]
o]   Scenario: Multiply two variables  # Multiplication.feature:6
o]     Given a variable x with value 2 # MultiplicationSteps.scala:17
o]     And a variable y with value 3   # MultiplicationSteps.scala:21
o]     When I multiply x * y           # MultiplicationSteps.scala:25
o]     Then I get 6                    # MultiplicationSteps.scala:29
o]
o] 1 Scenarios (1 passed)
o] 4 Steps (4 passed)
o] 0m0.106s
o]
cess] Total time: 1 s, completed 28-Dec-2015 22:16:19

The results will be output in the following formats:

Cucumber Plugin Arguments

Cucumber arguments may be supplied. For example, sbt "cucumber --tags ~@my-tag" will filter tagged feature files.

cess] Total time: 1 s, completed 15-Jun-2016 09:23:22
oa:cucumber-plugin-example lewismj$ sbt "cucumber --tags ~@my-tag"
o] Loading global plugins from /Users/lewismj/.sbt/0.13/plugins
o] Loading project definition from /Users/lewismj/github/cucumber/cucumber-plugin-example/project
o] Set current project to cucumber-test (in build file:/Users/lewismj/github/cucumber/cucumber-plugin-example/)
ello **
o] None of the features at [classpath:] matched the filters: [~@my-tag]
o] 
o] 0 Scenarios
o] 0 Steps
o] 0m0.000s
o] 
oodbye **
cess] Total time: 1 s, completed 15-Jun-2016 09:23:41
Properties

In your build.sbt file you can now specify environment variables as follows:

cumberPlugin.envProperties := Map("K"->"2049")

The setting expects a type of Map[String,String].


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.