项目作者: udaychandra

项目描述 :
JUnit 5 based BDD library to create and run stories and behaviors a.k.a BDD specification tests
高级语言: Java
项目地址: git://github.com/udaychandra/bdd.git
创建时间: 2018-07-11T03:49:19Z
项目社区:https://github.com/udaychandra/bdd

开源协议:Apache License 2.0

下载


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

    1. <dependency>
    2. <groupId>io.github.udaychandra.bdd</groupId>
    3. <artifactId>bdd-junit</artifactId>
    4. <version>0.1.0</version>
    5. <scope>test</scope>
    6. </dependency>
  • Gradle build.gradle

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

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

  1. import io.github.udaychandra.bdd.ext.Scenario;
  2. import io.github.udaychandra.bdd.ext.Story;
  3. @Story(name = "Returns go back to the stockpile",
  4. description = "As a store owner, in order to keep track of stock," +
  5. " I want to add items back to stock when they're returned.")
  6. public class StoreFrontTest {
  7. @Scenario("Refunded items should be returned to stock")
  8. public void refundAndRestock(Scene scene) {
  9. scene.
  10. given("that a customer previously bought a black sweater from me",
  11. () -> scene.put("store", new StoreFront(0, 4).buyBlack(1))).
  12. and("I have three black sweaters in stock",
  13. () -> assertEquals(3, scene.<StoreFront>get("store").getBlacks(),
  14. "Store should carry 3 black sweaters")).
  15. when("the customer returns the black sweater for a refund",
  16. () -> scene.<StoreFront>get("store").refundBlack(1)).
  17. then("I should have four black sweaters in stock",
  18. () -> assertEquals(4, scene.<StoreFront>get("store").getBlacks(),
  19. "Store should carry 4 black sweaters")).
  20. run();
  21. }
  22. }

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:

  1. STORY: Returns go back to the stockpile
  2. As a store owner, in order to keep track of stock, I want to add items back to stock when they're returned.
  3. SCENARIO: Refunded items should be returned to stock
  4. GIVEN that a customer previously bought a black sweater from me
  5. AND I have three black sweaters in stock
  6. WHEN the customer returns the black sweater for a refund
  7. 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
    1. gradlew clean build

You can read this InfoQ article for more insights.

License

Apache License 2.0