The test (specification) is initially created in Jira as a Cucumber Test and afterwards, it is exported using the UI or the REST API.
- npm packages
We aim to test the sum operation.
However, before moving into the actual implementation, you need to decide is which workflow we'll use: do we want to use Xray/Jira as the master for writing the declarative specification, or do we want to manage those in Git?
This tutorial only showcases using Xray/Jira as the master for editing the Cucumber Scenarios/Scenario Outlines.
Please see Testing in BDD with Gherkin based frameworks (e.g. Cucumber) for an overview of the possible workflows.
Using Jira and Xray as master
This section assumes using Xray as master, i.e. the place that you'll be using to edit the specifications (e.g. the scenarios that are part of .feature files).
The overall flow would be something like this:
- create Scenario/Scenario Outline as a Test in Jira; usually, it would be linked to an existing "requirement"/Story (i.e. created from the respective issue screen)
- implement the code related to Gherkin statements/steps and store it in Git, for example
- generate .feature files based on the specification made in Jira
- checkout the code from Git
- run the tests in the CI
- import the results back to Jira
Usually, you would start by having a Story, or similar (e.g. "requirement"), to describe the behavior of a certain feature and use that to drive your testing.
If you have it, then you can just use the "Create Test" on that issue to create the Scenario/Scenario Outline and have it automatically linked back to the Story/"requirement".
Otherwise, you can create the Test using the standard (issue) Create action from Jira's top menu.
In this case, we'll create a Cucumber Test, of Cucumber Type "Scenario".
We need to create the Test issue first and fill out the details on the next screen, from within the Test issue.
After the Test is created it will impact the coverage of related "requirement", if any.
The coverage and the test results can be tracked in the "requirement" side (e.g. user story). In this case, it changed from being UNCOVERED to NOTRUN (i.e. covered and with at least one test not run).
The related statement's code is managed outside of Jira and stored in Git, for example.
You can then export the specification of the test to a Cucumber .feature file via the REST API, or the Export to Cucumber UI action from within the Test/Test Execution issue or even based on an existing saved filter. A plugin for your CI tool of choice can be used to ease this task.
So, you can either:
- use the UI
- use the REST API (more info here)
- use one of the available CI/CD plugins (e.g. see an example of Integration with Jenkins)
After being exported, the created .feature(s) will contain references to the Test issue key and the covered "requirement" issue key, if that's the case. The naming of these files is detailed in Generate Cucumber Features.
To run the tests and produce a Cucumber JSON report, we can use the
After running the tests, results can be imported to Xray via the REST API, or the Import Execution Results action within the Test Execution, or by using one of the available CI/CD plugins (e.g. see an example of Integration with Jenkins).
Which Cucumber endpoint/"format" to use?
To import results, you can use two different endpoints/"formats" (endpoints described in Import Execution Results - REST):
- the "standard cucumber" endpoint
- the "multipart cucumber" endpoint
The standard cucumber endpoint (i.e. /import/execution/cucumber) is simpler but more restrictive: you cannot specify values for custom fields on the Test Execution that will be created. This endpoint creates new Test Execution issues unless the Feature contains a tag having an issue key of an existing Test Execution.
The multipart cucumber endpoint will allow you to customize fields (e.g. Fix Version, Test Plan), if you wish to do so, on the Test Execution that will be created. Note that this endpoint always creates new Test Executions (as of Xray v4.2).
In sum, if you want to customize the Fix Version, Test Plan and/or Test Environment of the Test Execution issue that will be created, you'll have to use the "multipart cucumber" endpoint.
A new Test Execution will be created (unless you originally exported the Scenarios/Scenario Outlines from a Test Execution).
The execution screen details of the Test Run will provide overall status information and Gherkin statement-level results; you'll need to click on the arrow to expand and see the detailed Gherkin statements.
Results are reflected on the covered item (e.g. Story). On its issue screen, coverage now shows that the item is OK based on the latest testing results, that can also be tracked within the Test Coverage panel bellow.
FAQ and Recommendations
Please see this page.
- Testing in BDD with Gherkin based frameworks (e.g. Cucumber)
- Automated Tests (Import/Export)
- Exporting Cucumber Tests - REST