Behavior-Driven Development in Plain Java

JGiven is a developer-friendly and pragmatic BDD tool for Java. Developers write scenarios in plain Java using a fluent, domain-specific API, JGiven generates reports that are readable by domain experts.

News

- Version 1.3.1 Released

- Version 1.3.0 Released

- Version 1.2.5 Released

More news…

Example

@Test
public void a_pancake_can_be_fried_out_of_an_egg_milk_and_flour() {
    given().an_egg().
        and().some_milk().
        and().the_ingredient( "flour" );

    when().the_cook_mangles_everything_to_a_dough().
        and().the_cook_fries_the_dough_in_a_pan();

    then().the_resulting_meal_is_a_pancake();
}

The above test can be executed like any JUnit test. During the execution, JSON files are generated that can then be used afterwards to generate test reports. By default, a plain text report is shown in the console, which would look as follows:

Scenario: a pancake can be fried out of an egg milk and flour

  Given an egg
    And some milk
    And the ingredient flour
   When the cook mangles everything to a dough
    And the cook fries the dough in a pan
   Then the resulting meal is a pan cake

Further examples can be found in the jgiven-examples module of JGiven.

HTML Report

Besides the plain text report, an HTML report can be generated. An example of such a report is JGiven’s own report:

JGiven HTML5 report of JGiven

The source code of the corresponding JGiven tests are in the jgiven-tests module of the JGiven project.

Key facts

  • Scenarios are written in plain Java with a fluent Java API - Neither text files, nor Groovy is needed
  • Method names are parsed at runtime and define the scenario text - No duplicate text in annotations is needed
  • Scenarios are executed by either JUnit or TestNG - No extra test runner is needed, thus JGiven works with all existing IDEs and build tools for Java out-of-the-box
  • Scenarios are composed of multiple, reusable so-called Stage classes - No more test code duplication
  • Scenarios and steps can be parameterized for writing data-driven tests
  • JGiven generates HTML reports that can be read and understand by domain experts and serve as a living documentation

Tools in Action Session on JGiven at Devoxx Belgium 2016

Jan Schäfer gave a Tools in Action session at Devoxx Belgium 2016. It mainly consists of a live demo showing how to refactor an existing JUnit test to use JGiven.

Talk on JGiven at Devoxx France 2016 (in French)

Marie-Laure Thuret (@mlthuret) and Clément Héliou (@c_heliou) did a live coding session with JGiven at Devoxx France 2016.

Talk on JGiven at BigTechday 8

Jan Schäfer gave a talk on JGiven at the BigTechday 8. It explains the rationale behind JGiven and gives an introduction into the main features of JGiven.