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 consist of multiple examples or scenarios. For more info on Cucumber, see here.

The Zephyr Squad/Cucumber Workflow

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

The below diagram shows how this works.

Using with CI server (e.g. Jenkins)

Cucumber_Integration.png

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

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

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 {

}

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

Uploading results to Zephyr Squad

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 Squad

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

https://github.com/SmartBear/zephyr-scale-cucumber-example

Publication date: