---
title: JBehave
description: Learn how to integrate Allure with JBehave to generate rich, interactive test reports. Follow step-by-step setup, test execution, and report generation guidance.
---

# Getting started with Allure JBehave

[![Allure JBehave latest version](https://img.shields.io/maven-central/v/io.qameta.allure/allure-jbehave?style=flat "allure-jbehave")](https://mvnrepository.com/artifact/io.qameta.allure/allure-jbehave)

Generate beautiful HTML reports using [Allure Report](https://allurereport.org/docs/) and
your [JBehave](https://jbehave.org/) tests.

Info:
Check out the example projects at [github.com/allure-examples](https://github.com/orgs/allure-examples/repositories?q=visibility%3Apublic+archived%3Afalse+topic%3Aexample+topic%3Ajbehave) to see Allure JBehave in action.

## Setting up

To integrate [Allure](https://allurereport.org) into an existing **JBehave** project, you need to:

1. Add Allure dependencies to your project.
1. Activate the Allure JBehave plugin.
1. Designate a location for Allure results storage.

### Adding Allure dependencies

**Maven:**
```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>
```

**Gradle (Kotlin):**
```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")
}
```

**Gradle (Groovy):**
```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](https://jbehave.org/reference/stable/developing-stories.html#configuring) 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`:

**Maven:**
```properties
#allure.properties
allure.results.directory=target/allure-results
```

**Gradle (Kotlin):**
```properties
#allure.properties
allure.results.directory=build/allure-results
```

**Gradle (Groovy):**
```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:

**MacOS/Linux:**
```bash
./gradlew test
```

**Windows:**
```bash
gradlew test
```

For Maven:

**MacOS/Linux:**
```bash
./mvnw verify
```

**Windows:**
```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 integration 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](#adding-metadata).
- **Test Organization**: Structure your tests into [clear hierarchies](#organize-tests) for better readability and organization.
- **Step Division**: Break down tests into smaller [test steps](#creating-sub-steps) for easier understanding and maintenance.
- **Parametrized Tests**: Clearly describe the parameters for [parametrized tests](#support-for-scenario-outlines) to specify different scenarios.
- **Attachments**: Automatically capture [screenshots and other files](#attaching-screenshots-and-other-files) during test execution.
- **Test Selection**: Use a test plan file to [select which tests to run](#selective-test-run-allure-testops), allowing for flexible test execution.
- **Environment Details**: Include comprehensive [environment information](#environment-information) to accompany the test report.

### Adding Metadata

Allure allows you to enrich your reports with a variety of [metadata](/docs/v2/readability/#description-links-and-other-metadata).
This additional information provides context and details for each test, enhancing the report's usefulness.
Refer to the [metadata reference section](/docs/jbehave-reference/#metadata)
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](/docs/v2/navigation/),
Allure JBehave supports this feature.

To specify a test's location in the [suite-based hierarchy](/docs/v2/navigation/#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:

1. **Annotated Sub-Steps**: Defined using `@Step` annotation.
2. **Lambda Sub-Steps**: Utilizing lambda expressions for more concise and inline step definitions.
3. **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](/docs/jbehave-reference/#test-steps).

**Annotated sub-steps:**
```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() {
        // ...
    }
}
```

**Lambda steps and no-op sub-steps:**
```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](https://jbehave.org/reference/stable/parametrised-scenarios.html),
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](/docs/v2/readability/#screenshots-and-other-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](/docs/jbehave-reference/#attachments).

```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 integration.

### 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.

Images: /images/java/environment-allure3.png, /images/java/environment-allure2.png

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](/docs/how-it-works-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](/docs/jbehave-reference/#parametrized-tests).
