Overview
In this tutorial, we will create some tests in Cucumber for Java.
In this case, the test (specification) is initialy created in JIRA as a Cucumber Test and afterwards is exported using the UI or the REST API.
Requirements
- install Java
- add the dependency "cucumber-jvm" to your maven "pom.xml" file
- clone of the Github repository "cucumber-java-skeleton"
Description
We will use the code from the Github repository "cucumber-java-skeleton", with some slight changes, in order to make the dummy Test pass.
So the first step is to create create a Cucumber Test, of Cucumber Type "Scenario", in JIRA. The specification would be exactly the same as the one provided in the original repository.
After we create the Test in JIRA, and associate it with requirements, etc, you can export the specification of the test to a Cucumber .feature file (e.g. by REST API or by the UI action "Export to Cucumber" from within the Test Execution issue).
The created file will be similar to the original one but will contain the references to the Test issue key and the covered requirement issue key.
@ABC-100 Feature: Belly @ABC-122 Scenario: a few cukes Given I have 42 cukes in my belly When I wait 1 hour Then my belly should growl
We can change the steps implementation just in order to make them quickly pass.
package skeleton; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; public class Stepdefs { @Given("^I have (\\d+) cukes in my belly$") public void I_have_cukes_in_my_belly(int cukes) throws Throwable { Belly belly = new Belly(); belly.eat(cukes); } @When("^I wait (\\d+) hour$") public void I_wait_hours(int hours) throws Throwable { Thread.sleep(hours*0); } @Then("^my belly should growl$") public boolean my_belly_should_growl() throws Throwable { return true; } }
After running the tests (see bellow) and generating the Cucumber JSON report (e.g. data.json), it can be imported to Xray (either by the REST API or through "Import Execution Results" action within the Test Execution).
mvn compile test -Dcucumber.options="-p json:data.json"
The execution screen details will provide information of the test run result.
The Cucumber Scenarios Example/Result details(Hooks, Backgrounds and Steps), are only available for executions made with Xray v2.2.0 and above.
The icon represents the evidences ("embeddings") for each (Hooks, Backgrounds and Steps) , but are only available for executions made with Xray v2.3.0 and above.
Learn more
Please see Testing with Cucumber for a high level overview on how to use Cucumber Tests with Xray.
References
- https://cucumber.io/docs/reference/jvm#java
- https://github.com/cucumber/cucumber-java-skeleton
- Automated Tests (Import/Export)
- Exporting Cucumber Tests - REST