BDD Requirements Management with JBehave, Thucydides and JIRA
BDD Requirements Management with JBehave, Thucydides and JIRA
Join the DZone community and get the full member experience.Join For Free
DevOps involves integrating development, testing, deployment and release cycles into a collaborative process. Learn more about the 4 steps to an effective DevSecOps infrastructure.
Getting started with Thucydides/JIRA integration
JIRA is a popular issue tracking system that is also often used for Agile project and requirements management. Many teams using JIRA store their requirements electronically in the form of story cards and epics in JIRA
Suppose we are implementing a Frequent Flyer application for an airline. The idea is that travellers will earn points when they fly with our airline, based on the distance they fly. Travellers start out with a "Bronze" status, and can earn a better status by flying more frequently. Travellers with a higher frequent flyer status benefit from advantages such as lounge access, prioritized boarding, and so on. One of the story cards for this feature might look like the following:
This story contains a description following one of the frequently-used formats for user story descriptions ("as a..I want..so that"). It also contains a custom "Acceptance Criteria" field, where we can write down a brief outline of the "definition of done" for this story.
These stories can be grouped into epics, and placed into sprints for project planning, as illustrated in the JIRA Agile board shown here:
As illustrated in the story card, each of these stories has a set of acceptance criteria, which we can build into more detailed scenarios, based on concrete examples. We can then automate these scenarios using a BDD tool like JBehave.
The story in Figure 1 describes how many points members need to earn to be awarded each status level. A JBehave scenario for the story card illustrated earlier might look like this:
Frequent Flyer status is calculated based on points Meta: @issue FH-17 Scenario: New members should start out as Bronze members Given Jill Smith is not a Frequent Flyer member When she registers on the Frequent Flyer program Then she should have a status of Bronze Scenario: Members should get status updates based on status points earned Given a member has a status of <initialStatus> And he has <initialStatusPoints> status points When he earns <extraPoints> extra status points Then he should have a status of <finalStatus> Examples: | initialStatus | initialStatusPoints | extraPoints | finalStatus | notes | | Bronze | 0 | 300 | Silver | 300 points for Silver | | Silver | 0 | 700 | Gold | 700 points for Gold | | Gold | 0 | 1500 | Platinum | 1500 points for Platinum |
Thucydides lets you associate JBehave stories or JUnit tests with a JIRA card using the @issue meta tag (illustrated above), or the equivalent @Issue annotation in JUnit. At the most basic level, this will generate links back to the corresponding JIRA cards in your test reports, as illustrated here:
For this to work, Thucydides needs to know where your JIRA server. The simplest way to do this is to define the following properties in a file called thucydides.properties in your project root directory:
jira.url=https://myserver.atlassian.net jira.project=FH jira.username=jirauser jira.password=t0psecret
You can also set these properties up in your Maven pom.xml file or pass them in as system properties.
Thucydides also supports two-way integration with JIRA. You can also get Thucydides to update the JIRA issue with a comment pointing to the corresponding test result.
But test results only report part of the picture. If you are using JIRA to store your stories and epics, you can use these to keep track of progress. But how do you know what automated acceptance tests have been implemented for your stories and epics, and, equally importantly, how do you know which stories or epics have no automated acceptance tests? In agile terms, a story cannot be declared "done" until the automated acceptance tests pass. Furthermore, we need to be confident not only that the tests exist, but they test the right requirements, and that they test them sufficiently well.
We call this idea of measuring the number (and quality) of the acceptance tests for each of the features we want to build "feature coverage". Thucydides can provide feature coverage reporting in addition to the more conventional test results. If you are using JIRA, you will need to add thucydides-jira-requirements-provider to the dependencies section of your pom.xml file:
<dependencies> ... <dependency> <groupId>net.thucydides.plugins.jira</groupId> <artifactId>thucydides-jira-requirements-provider</artifactId> <version>0.9.260</version> </dependency> </dependencies>
(The actual version number might be different for you - always take a look at Maven Central to know what the latest version is).
You will also need to add this dependency to the Thucydides reporting plugin configuration:
<build> ... <plugins> ... <plugin> <groupId>net.thucydides.maven.plugins</groupId> <artifactId>maven-thucydides-plugin</artifactId> <version>0.9.257</version> <executions> <execution> <id>thucydides-reports</id> <phase>post-integration-test</phase> <goals> <goal>aggregate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>net.thucydides.plugins.jira</groupId> <artifactId>thucydides-jira-requirements-provider</artifactId> <version>0.9.260</version> </dependency> </dependencies> </plugin> </plugins> </build>Now, when you run the tests, Thucydides will query JIRA to determine the epics and stories that you have defined, and list them in the Requirements page. This page gives you an overview of how many requirements (epics and stories) have passing tests (green), how many have failing (red) or broken (orange) tests, and how many have no tests at all (blue):
If you click on an epic, you can see the stories defined for the epic, including an indicator (in the "Coverage" column) of how well each story has been tested.
From here, you may want to drill down into the details about a given story, including what acceptance tests have been defined for this story, and whether they ran successfully:
Both JIRA and the JIRA-Thucydides integration are quite flexible. We saw earlier that we had configured a custom "Acceptance Criteria" field in our JIRA stories. We have displayed this custom field in the report shown above by including it in the thucydides.properties file, like this:
Thuydides reads the narrative text appearing in this report ("As a frequent flyer…") from the Description field of the corresponding JIRA card. We can override this behavior and get Thucydides to read this value from a different custom field using the jira.custom.narrative.field property. For example, some teams use a custom field called "User Story" to store the narrative text, instead of the Description field. We could get Thucydides to use this field as follows:
Thucydides has rich and flexible one and two-way integration with JIRA. Not only can you link back to JIRA story cards from your acceptance test reports and display information about stories from JIRA in the test reports, you can also read the requirements structure from JIRA, and report on which features have been tested, and which have not.
In the next article in this series, we will learn how to insert links to the Thucydides reports into the JIRA issues, and how to actively update the state of the JIRA cards based on the outcomes of your tests.
Published at DZone with permission of John Ferguson Smart , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.