Appearance
Getting started with Allure JBehave
Generate beautiful HTML reports using Allure Report and your JBehave tests.
INFO
Check out the example projects at github.com/allure-examples to see Allure JBehave in action.
Setting up
To integrate Allure into an existing JBehave project, you need to:
- Add Allure dependencies to your project.
- Activate the Allure JBehave plugin.
- Designate a location for Allure results storage.
Adding Allure dependencies
xml
<!-- Define the version of Allure you want to use via the allure.version property -->
<properties>
<allure.version>2.24.0</allure.version>
</properties>
<!-- Add allure-bom to dependency management to ensure correct versions of all the dependencies are used -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-bom</artifactId>
<version>${allure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Add necessary Allure dependencies to dependencies section -->
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-jbehave5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
kts
// Define the version of Allure you want to use via the allureVersion property
val allureVersion = "2.24.0"
// ...
dependencies {
// Import allure-bom to ensure correct versions of all the dependencies are used
testImplementation(platform("io.qameta.allure:allure-bom:$allureVersion"))
// Add necessary Allure dependencies to dependencies section
testImplementation("io.qameta.allure:allure-jbehave5")
}
groovy
// Define the version of Allure you want to use via the allureVersion property
def allureVersion = "2.24.0"
dependencies {
// Import allure-bom to ensure correct versions of all the dependencies are used
testImplementation platform("io.qameta.allure:allure-bom:$allureVersion")
// Add necessary Allure dependencies to dependencies section
testImplementation "io.qameta.allure:allure-jbehave5"
}
Enabling Allure JBehave plugin
In your Embeddable class (such as a JUnitStories
-based class), add the AllureJbehave5
reporter to the configuration object.
java
import io.qameta.allure.jbehave5.AllureJbehave5;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.StoryReporterBuilder;
public class Stories extends JUnitStories {
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryReporterBuilder(new StoryReporterBuilder()
.withReporters(new AllureJbehave5()));
}
// ...
}
Specifying Allure Results location
Allure, by default, saves test results in the project's root directory. However, it is recommended to store your test results in the build output directory.
To configure this, create an allure.properties
file and place it in the test resources directory of your project, which is typically located at src/test/resources
:
properties
#allure.properties
allure.results.directory=target/allure-results
properties
#allure.properties
allure.results.directory=build/allure-results
properties
#allure.properties
allure.results.directory=build/allure-results
Running tests
Execute your JBehave tests as you normally would. Below are the commands for Gradle and Maven users:
For Gradle:
bash
./gradlew test
bash
gradlew test
For Maven:
bash
./mvnw verify
bash
mvnw verify
After running the tests, Allure will gather the test execution data and store it in the allure-results
directory. You can then generate an HTML report from these results using Allure's reporting tools.
Writing tests
The Allure JBehave adapter extends the standard reporting features of JBehave by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:
- Metadata Annotation: Enhance test reports with descriptions, links, and other metadata.
- Test Organization: Structure your tests into clear hierarchies for better readability and organization.
- Step Division: Break down tests into smaller test steps for easier understanding and maintenance.
- Parametrized Tests: Clearly describe the parameters for parametrized tests to specify different scenarios.
- Attachments: Automatically capture screenshots and other files during test execution.
- Test Selection: Use a test plan file to select which tests to run, allowing for flexible test execution.
- Environment Details: Include comprehensive environment information to accompany the test report.
Adding Metadata
Allure allows you to enrich your reports with a variety of metadata. This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the metadata reference section for an exhaustive list of what can be added.
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
public class JBehaveSteps {
@When("I open labels page")
public void openLabelsPage() {
Allure.description("This test attempts to create a label with specified title");
Allure.label("owner", "John Doe");
Allure.label("severity", "critical");
Allure.link("Website", "https://dev.example.com/");
Allure.issue("AUTH-123", "https://example.com/issues/AUTH-123");
Allure.tms("TMS-456", "https://example.com/tms/TMS-456");
// ...
}
}
Organize tests
Allure facilitates enhanced navigation in test reports by allowing tests to be organized into hierarchical structures. As explained in the section on Improving navigation in your test report, Allure JBehave supports this feature.
To specify a test's location in the suite-based hierarchy:
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
public class JBehaveSteps {
@When("I open labels page")
public void openLabelsPage() {
Allure.label("parentSuite", "Tests for web interface");
Allure.suite("Tests for essential features");
Allure.label("subSuite", "Tests for labels");
// ...
}
}
Creating Sub-Steps
Allure JBehave enhances test reports by allowing the creation of sub-steps within a single JBehave step, which can be particularly useful in cases where you have a set of actions that are:
- Sufficiently cohesive to be described as one step in a story file.
- Intricate enough that they involve several potential failure points.
Allure provides three methods for defining sub-steps:
- Annotated Sub-Steps: Defined using
@Step
annotation. - Lambda Sub-Steps: Utilizing lambda expressions for more concise and inline step definitions.
- No-Op Sub-Steps: Employed as placeholders or for structuring steps without additional functionality.
For detailed guidance on implementing each type of sub-step, consult the test steps reference.
java
import io.qameta.allure.Step;
import org.jbehave.core.annotations.Then;
public class JBehaveSteps {
@When("I open labels page")
public void openLabelsPage() {
step1();
step2();
}
@Step("Step 1")
public void step1() {
subStep1();
subStep2();
}
@Step("Sub-step 1")
public void subStep1() {
// ...
}
@Step("Sub-step 2")
public void subStep2() {
// ...
}
@Step("Step 2")
public void step2() {
// ...
}
}
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
public class JBehaveSteps {
@When("I open labels page")
public void openLabelsPage() {
Allure.step("Step 1", (step) -> {
// ...
Allure.step("Sub-step 1");
// ...
Allure.step("Sub-step 2");
});
Allure.step("Step 2", (step) -> {
// ...
});
}
}
Support for Scenario Outlines
Allure JBehave provides complete support for Scenario Outlines, a feature of JBehave that allows for parametrized tests. No special setup is needed to take advantage of this capability within Allure.
Scenario: Registration
When I go to the registration form
And I enter my details: <login>, <password>, <name>, <birthday>
Then the profile should be created
Examples:
| login | password | name | birthday |
| johndoe | qwerty | John Doe | 1970-01-01 |
| janedoe | 123456 | Jane Doe | 1111-11-11 |
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
public class JBehaveSteps {
@When("I go to the registration form")
public void goToRegistrationForm() {
// ...
}
@When("I enter my details: $login, $password, $name, $birthday")
public void enterMyDetails() {
// ...
}
@Then("the profile should be created")
public void profileShouldBeCreated() {
// ...
}
}
Furthermore, Allure's Runtime API can be utilized to include extra parameters in the test report, offering enhanced documentation capabilities and greater detail for each test scenario:
Scenario: Registration
When I go to the registration form
And I enter my details
Then the profile should be created
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
public class JBehaveSteps {
@When("I go to the registration form")
public void goToRegistrationForm() {
// ...
}
@When("I enter my details")
public void enterMyDetails() {
Allure.parameter("login", "johndoe");
Allure.parameter("password", "qwerty");
Allure.parameter("name", "John Doe");
Allure.parameter("birthday", "1970-01-01");
// ...
}
@Then("the profile should be created")
public void profileShouldBeCreated() {
// ...
}
}
Attaching screenshots and other files
In Allure reports, you have the ability to attach various types of files, which can greatly enhance the comprehensibility of the report. A common practice is to attach screenshots that capture the state of the user interface at specific moments during test execution.
Allure JBehave offers multiple methods for creating attachments, whether from pre-existing files or from content generated on-the-fly. For detailed instructions on how to implement attachments, refer to the attachments section in the Allure JBehave reference.
java
import io.qameta.allure.Allure;
import org.jbehave.core.annotations.Then;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class JBehaveSteps {
@When("I open labels page")
public void openLabelsPage() throws IOException {
// ...
Allure.attachment("data.txt", "This is the file content.");
Allure.attachment("img.png", Files.newInputStream(Paths.get("/path/img.png")));
}
}
Selective test run (Allure TestOps)
DANGER
Test plan is currently not supported by the Allure JBehave adapter.
Environment information
For the main page of the report, you can collect various information about the environment in which the tests were executed.
For example, it is a good idea to use this to remember the OS and Java versions. This may help the future reader investigate bugs that are reproducible only in some environments.
To provide environment information, put a file named environment.properties
into the allure-results
directory after running the tests. See the example in Environment file.
Note that this feature should be used for properties that do not change for all tests in the report. If you have properties that can be different for different tests, consider using Parametrized tests.