Cucumber Integration

Cucumber is a tool that supports Behaviour-Driven Development(BDD). If you’re new to Behaviour-Driven Development read our BDD introduction first.

Cucumber reads executable specifications written in plain text and validates that the software does what those specifications say. The specifications consists of multiple examples, or scenarios. For more info on Cucumber, see here.

The Zephyr Scale/Cucumber Workflow

If you’re using Cucumber, Zephyr Scale allows you to tightly integrate with your automated tests. You can write BDD test cases (gherkin scripts) in Zephyr Scale and use a simple script to export these tests when running a build before sending the results back to Zephyr Scale.

The below diagram shows how this works.

Using with CI server (e.g. Jenkins)

64107f1063ef8.png

Properly annotating Cucumber tests enables results from Cucumber to be sent directly to the correspongin test cases in Zephyr Scale.

Writing Cucumber tests

Cucumber tests are written in Gherkin - a set of grammar rules that makes plain text structured enough for Cucumber to understand.

Gherkin documents are stored in .feature text files and are typically versioned in source control alongside the software. See the Gherkin reference for more details.

Once you have written your scenarios, you can simply annotate them by adding a tag such as@TestCaseKey=ABC-T123. In this example, Zephyr scale will then map the results of this Cucumber scenario to the corresponding test case with the key ABC-T123.

Feature: Calculator

  @TestCaseKey=ABC-T123
  Scenario: Add a number
    Given a calculator I just turned on
    And I add 4 and 4
    Then the result is 8

If the test Case doesn't exist yet, there is no need for annotation

## Add a header here for executing your test

Firstly, the JSON output format for Cucumber needs to be configured on the TestRunner class:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/resources/calculatorFeatures"
        ,glue={"com/adaptavist/tm4j/cucumberExample/stepDefinition"}
        ,plugin = {"junit:target/cucumber/result.xml", "json:target/cucumber/calculator.json"}
)

public class TestRunner {

}

On the example above, both JUnit XML and JSON output are enabled.

Uploading results to Zephyr Scale

Now, you can run your tests with mvn test and the Cucumber execution results will be generated in target/cucumber/*.json.

Mapping a status to Zephyr Scale

We now support all Cucumber statuses. They will map automatically to an existing status or show as Blocked if a matching custom status doesn't exist.

Code samples

64107f125ccac.pngSmartBear/zephyr-scale-cucumber-example

Suggested Improvements

Is something missing? If you’d like to suggest an improvement to this integration, take a look at our Ideas Portal.

You can search for existing ideas or create your own. We review ideas regularly and will take them into account for future development.

Publication date: