BDD Execution Listener

This is a JUnit5 plugin that listens for tests whose names follow the Given...When...Then syntax and converts these test results into scenario models to be serialized. This library doesn't produce any output on its own, but rather looks for plugins that will serialize these scenarios. Currently there is only an HTML plugin.

Maven Information

<groupId>io.bitbucket.tomwnorton</groupId>
<artifactId>bdd-execution-listener</artifiactId>
<version>1.0</version>
            

Organizing Your Tests

This code example showcases the several ways you can arrange your JUnit5 tests for this plugin to work.
@DisplayName("Given a user wants to place an order")
class OrderPlacementServiceTest {
    ...
    @DisplayName("Given the user is not logged in")
    @Nested
    class UserNotLoggedIn {
        ...
        @DisplayName("When the user tries to place the order then give them a 401 response")
        @Test
        void it_returns_401_response() {
            ...
        }
    }

    @DisplayName("Given the user is logged in")
    @Nested
    class UserIsLoggedIn {
        ...
        @DisplayName("When the user places the order")
        @Nested
        class OrderIsPlaced {
            ...
            @DisplayName("Then the order is saved to the database")
            @Test
            void it_saves_record_to_database() {
                ...
            }

            @DisplayName("Then the user is notified of the successful placement")
            @Test
            void it_notifies_the_user() {
                ...
            }
        }
    }
}
        
This code will be transformed into the following scenarios:
Given a user wants to place an order
Given the user is not logged in
When the user tries to place the order
Then give them a 401 response

Given a user wants to place an order
Given the user is logged in
When the user places the order
Then the order is saved to the database
Then the user is notified of the successful placement
        
There are a few things to note here:
  • The Given, When, and Then keywords are case-insensitive
  • As many Given, and When classes may be as nested as you wish
  • The Then keyword may only be used inside test methods
  • Any tests or test classes that do not conform to the Given...When...Then format will be ignored
  • The library will ignore any dynamic tests or test templates (junit-jupiter-params is an implementation of a test template) yet.

Serializing to Custom Formats

Follow the instructions in the javadocs.