Coder Social home page Coder Social logo

cucumber-jvm-scala-example's Introduction

Cucumber JVM Scala Example Build Status

About

This is an example Cucumber-JVM project.

  • Uses Scala step definitions

  • Packages tests into executable jar file

Getting Started

If you’re new to Cucumber testing, start with https://cucumber.io/docs. Otherwise, run the example test in IDE or command line (see Running Cucumber Tests).

Essential Elements

  • Feature files - contains the BDD feature definitions (Gherkin, e.g. Example.feature)

  • Step definitions - Implementation of the step definitions (Scala, e.g. ExampleSteps.scala)

  • CucumberTestMain - this is the program entry point when tests are packaged as executable jar file (e.g. target/cucumber-jvm-scala-example.jar)

  • Test runners - run specific feature set ( Scala with Junit annotations, e.g. ExampleTestRunner.scala). This is only used when developing tests.

Creating Tests

Intellij :

  • Install Scala plugin

  • Install Cucumber for Scala plugin (allows easy navigation of glue steps)

  • Create or update feature file in src/main/resources/features

  • Create or update test runner in src/test/scala/runner with the appropriate tags

  • Implement or update steps in src/main/scala/steps

Creating Feature Files

Example
Feature: Example feature

  @ExampleFeature
  Scenario: Example scenario
    Given this pre condition
    And this pre condition
    When I do this
    And I do this
    Then I can verify that
    And I can also verify that

Creating Test Runner

See the example below and change the appropriate values of the CucumberOptions annotation.

@RunWith(classOf[Cucumber])
@CucumberOptions(
  features = Array("classpath:features/Example.feature"),
  tags = Array("~@Wip"),
  glue = Array("classpath:steps"),
  plugin = Array("pretty", "html:target/cucumber/html"))
class ExampleFeatureRunner
  • This runs all scenarios in Example.feature not tagged with @Wip

  • The step definitions are loaded from class path steps

  • This generates reports in target/cucumber/html folder relative to some execution path

ANDing, NEGating, and ORing Cucumber Tags

  • ~ negates a tag

  • Comma separated tags are ORed (example tags = Array("@FeatureSet1,@FeatureSet2") means run both feature sets)

  • Separated tags are ANDed (example tags = Array("~@Wip","@FeatureSet1") means run @FeatureSet1 but not those tagged with @Wip)

Implementing Steps/Glue

After you created the feature files, run the test runner, it will give you hints on the missing steps you need to implement

Example (ExampleSteps.scala)

Given("""^this pre condition$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
  When("""^I do this$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
  Then("""^I can verify that$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
  Then("""^I can also verify that$""") { () =>
    //// Write code here that turns the phrase above into concrete actions
  }
}

Running Cucumber Tests in CLI

Using maven test:

mvn test

Using executable jar file:

mvn clean package
java -jar target/cucumber-jvm-scala-example.jar --plugin pretty --plugin html:cucumber/html --json json:cucumber/json/cucumber.json  --glue steps classpath:features --tags ~@Wip

or using cucumber.options environment variable:

mvn clean package
java -Dcucumber.options="--plugin pretty --plugin html:cucumber/html  --plugin json:cucumber/json/cucumber.json  --tags ~@Wip --glue steps classpath:features" -jar target/cucumber-jvm-scala-example.jar

Using maven exec:plugin:

mvn exec:java -Dcucumber.options="--plugin pretty --plugin html:cucumber/html --plugin json:cucumber/json/cucumber.json --tags ~@Wip --tags @ExampleFeature"

The above command line examples generate reports in cucumber/html and in cucumber/json directories

Running Cucumber Tests in IDE (Intellij IDEA)

In the Run/Debug Configuration , add the steps directories (in this example, steps) in the Glue text field.

Sharing State In Steps

  • A number of options here, instance variables, thread local map, or containers

cucumber-jvm-scala-example's People

Contributors

jecklgamis avatar filfreire avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.