Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/udaychandra/bdd
JUnit 5 based BDD library to create and run stories and behaviors a.k.a BDD specification tests
https://github.com/udaychandra/bdd
bdd bdd-framework java junit junit5
Last synced: about 1 month ago
JSON representation
JUnit 5 based BDD library to create and run stories and behaviors a.k.a BDD specification tests
- Host: GitHub
- URL: https://github.com/udaychandra/bdd
- Owner: udaychandra
- License: apache-2.0
- Created: 2018-07-11T03:49:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-05T02:20:47.000Z (almost 6 years ago)
- Last Synced: 2024-03-15T09:43:11.585Z (9 months ago)
- Topics: bdd, bdd-framework, java, junit, junit5
- Language: Java
- Homepage:
- Size: 111 KB
- Stars: 25
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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](https://junit.org/junit5/docs/current/user-guide/#installation) 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
```xml
io.github.udaychandra.bdd
bdd-junit
0.1.0
test
```- Gradle build.gradle
```groovy
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:
```java
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.get("store").getBlacks(),
"Store should carry 3 black sweaters")).when("the customer returns the black sweater for a refund",
() -> scene.get("store").refundBlack(1)).then("I should have four black sweaters in stock",
() -> assertEquals(4, scene.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:
```text
STORY: Returns go back to the stockpileAs 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
```bash
gradlew clean build
```You can read this InfoQ [article](https://www.infoq.com/articles/deep-dive-junit5-extensions) for more insights.
## License
Apache License 2.0