Page History
...
Your specification is made using Gherkin (i.e. Given, When, That) statements in Scenario(s) or Scenario Outline(s), eventually complemented with a Background. Implementation of each Gherkin statement (i.e. "step") is done in code; the Cucumber framework finds the code based on regular or cucumber expressions.
Note | ||||||
---|---|---|---|---|---|---|
| ||||||
Code is available in GiHub; the repo contains some auxiliary scripts. |
Usage scenarios
Cucumber is used in diverse scenarios. Next you may find some usage patterns, even though Cucumber usage is mostly recommended only if you are adopting BDD.
...
Code Block | ||
---|---|---|
| ||
mvn compile test -Dcucumber.plugin="json:report.json" -Dcucumber.features="features/" |
This will produce one Cucumber JSON report with all results.
...
Info | ||||
---|---|---|---|---|
| ||||
As the report format in Cucumber JSON is being deprecated in favour of Cucumber Messages, a protocol buffer based implementation, the previous command needs to be adapted slightly. The report starts by being generated in Cucumber Messages, using "-f message" argument, and then converted to the legacy Cucumber JSON report using the tool cucumber-json-formatter.
| ||||
title | example of a Bash script to import results using the standard Cucumber endpoint | |||
collapse | true | |||
curl -H "Content-Type: application/json" -X POST -u admin:admin --data @"report.json" http://jiraserver.example.com/rest/raven/1.0/import/execution/cucumber |
|
This will produce one Cucumber JSON report with all results.
After running the tests, results can be imported to Xray via the REST API, or the Import Execution Results action within an existing Test Execution, or by using one of the available CI/CD plugins (e.g. see an example of Integration with Jenkins).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -H "Content-Type: application/json" -X POST -u admin:admin --data @"report.json" http://jiraserver.example.com/rest/raven/1.0/import/execution/cucumber |
Info | ||
---|---|---|
| ||
To import results, you can use two different endpoints/"formats" (endpoints described in Import Execution Results - REST):
The standard cucumber endpoint (i.e. / | ||
Info | ||
| ||
To import results, you can use two different endpoints/"formats" (endpoints described in Import Execution Results - REST):
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. |
...
Code Block | ||||
---|---|---|---|---|
| ||||
@REQ_CALC-7935
Feature: As a user, I can multiply two numbers
#As a user, I can multiply two numbers
#simple integer multiplication
@TEST_CALC-7936
Scenario: simple integer multiplication
Given I have entered 3 into the calculator
And I have entered 0 into the calculator
When I press multiply
Then the result should be 0 on the screen |
...
When I press multiply
Then the result should be 0 on the screen |
To run the tests and produce a Cucumber JSON report, we can run Maven and specify that we want a report in Cucumber JSON format and that it should process .features from the features/
directory.
Code Block | ||
---|---|---|
| ||
mvn compile test -Dcucumber.plugin="json:report.json" -Dcucumber.features="features/" |
Info | ||||||
---|---|---|---|---|---|---|
| ||||||
As the report format in Cucumber JSON is being deprecated in favour of Cucumber Messages, a protocol buffer based implementation, the previous command needs to be adapted slightly. The report starts by being generated in Cucumber Messages, using "-f message" argument, and then converted to the legacy Cucumber JSON report using the tool cucumber-json-formatter.
|
This will produce one Cucumber JSON report with all results.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
public static int Multiply(int num1, int num2 ) { return num1 * num2; } |
FAQ and Recommendations
Please see this page.
References
- Code used in this tutorial, along with some auxiliary scripts
- Sample project cucumber-java-skeleton
- Official Cucumber documentation
- Cucumber installation instructions for Java
- Cucumber API
- Cucumber expressions
- Testing in BDD with Gherkin based frameworks (e.g. Cucumber)
- Automated Tests (Import/Export)
- Exporting Cucumber Tests - REST
...