UD BDD library

A light weight JUnit 5 based BDD library to create and run stories and behaviors

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

io.github.udaychandra.bdd
ArtifactId

ArtifactId

bdd-junit
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

UD BDD library
A light weight JUnit 5 based BDD library to create and run stories and behaviors
Project URL

Project URL

https://github.com/udaychandra/bdd
Source Code Management

Source Code Management

https://github.com/udaychandra/bdd

Download bdd-junit

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.udaychandra.bdd/bdd-junit/ -->
<dependency>
    <groupId>io.github.udaychandra.bdd</groupId>
    <artifactId>bdd-junit</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.udaychandra.bdd/bdd-junit/
implementation 'io.github.udaychandra.bdd:bdd-junit:0.1.1'
// https://jarcasting.com/artifacts/io.github.udaychandra.bdd/bdd-junit/
implementation ("io.github.udaychandra.bdd:bdd-junit:0.1.1")
'io.github.udaychandra.bdd:bdd-junit:jar:0.1.1'
<dependency org="io.github.udaychandra.bdd" name="bdd-junit" rev="0.1.1">
  <artifact name="bdd-junit" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.udaychandra.bdd', module='bdd-junit', version='0.1.1')
)
libraryDependencies += "io.github.udaychandra.bdd" % "bdd-junit" % "0.1.1"
[io.github.udaychandra.bdd/bdd-junit "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
io.github.udaychandra.bdd : bdd-core jar 0.1.1
org.junit.jupiter : junit-jupiter-api jar 5.3.2

Project Modules

There are no modules declared in this project.

BDD

A BDD library that provides a custom extension based on JUnit 5 Jupiter Extension Model. This library can be used to create and run stories and behaviors a.k.a BDD specification tests.

Basic Usage

You need to add JUnit 5 dependencies before using this library. If you are using a build tool like Maven or Gradle, add the following dependency after setting-up JUnit:

  • Maven pom.xml

     <dependency>
       <groupId>io.github.udaychandra.bdd</groupId>
       <artifactId>bdd-junit</artifactId>
       <version>0.1.0</version>
       <scope>test</scope>
     </dependency>
  • Gradle build.gradle

     dependencies {
       testImplementation 'io.github.udaychandra.bdd:bdd-junit:0.1.0'
     }

You can now write stories using @Story and @Scenario annotations provided by this library. Here's an example:

import io.github.udaychandra.bdd.ext.Scenario;
import io.github.udaychandra.bdd.ext.Story;

@Story(name = "Returns go back to the stockpile",
        description = "As a store owner, in order to keep track of stock," +
                " I want to add items back to stock when they're returned.")
public class StoreFrontTest {

    @Scenario("Refunded items should be returned to stock")
    public void refundAndRestock(Scene scene) {
        scene.
            given("that a customer previously bought a black sweater from me",
                    () -> scene.put("store", new StoreFront(0, 4).buyBlack(1))).

            and("I have three black sweaters in stock",
                    () -> assertEquals(3, scene.<StoreFront>get("store").getBlacks(),
                            "Store should carry 3 black sweaters")).

            when("the customer returns the black sweater for a refund",
                    () -> scene.<StoreFront>get("store").refundBlack(1)).

            then("I should have four black sweaters in stock",
                    () -> assertEquals(4, scene.<StoreFront>get("store").getBlacks(),
                            "Store should carry 4 black sweaters")).
            run();
    }
}

The "Scene" object injected into each test method can be used to store and retrieve arbitrary objects.

When you run these stories (tests), text reports like the one shown below are generated:

STORY: Returns go back to the stockpile

As a store owner, in order to keep track of stock, I want to add items back to stock when they're returned.

SCENARIO: Refunded items should be returned to stock
   GIVEN that a customer previously bought a black sweater from me
     AND I have three black sweaters in stock
    WHEN the customer returns the black sweater for a refund
    THEN I should have four black sweaters in stock

You will find the text reports in a folder named "bdd-reports" located under your test classes build folder.

Development

This is a community project. All contributions are welcome.

To start contributing, do the following:

  • Install JDK 8+
  • Fork or clone the source code
  • Run the build using the gradle wrapper
gradlew clean build

You can read this InfoQ article for more insights.

License

Apache License 2.0

Versions

Version
0.1.1
0.1.0