Behavior-Driven Development in plain Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
develop remove unsupported checkstyle rules Oct 3, 2017
docs Fix typo in user guide #359 Jul 28, 2018
example-projects Update JUnit 5 examples, by using built-in Gradle support fixes #340 May 20, 2018
gradle/wrapper Upgrade ByteBuddy, Gradle, Jacoco to support Java 10 #345 May 20, 2018
jgiven-android-test upgrade to gradle v3.3 Feb 11, 2017
jgiven-android upgrade android gradle plugin to version 2.3.3 Oct 3, 2017
jgiven-core Array formatting example #351 Jul 28, 2018
jgiven-examples #318 Jun 15, 2017
jgiven-gradle-plugin update gradle publish plugin Jul 28, 2018
jgiven-html-app Download HTML App from npm Aug 19, 2017
jgiven-html5-report fixed logger to use in Html5ReportGenerator Feb 16, 2018
jgiven-java8-tests Initial work to enable the parallel execution of testng data providers ( Aug 28, 2015
jgiven-java9-tests Removed usages of javax.xml.bind classes #324 Oct 8, 2017
jgiven-junit fix typo #364 Aug 15, 2018
jgiven-junit5 fix issue with JUnit 5 where a test class has only disabled methods, … May 20, 2018
jgiven-maven-plugin fix issue in build of maven plugin Oct 8, 2017
jgiven-spock Add support for Spock. Jul 14, 2018
jgiven-spring Make gradle-plugin and android projects compile again Feb 11, 2017
jgiven-testng Handle TestNG SkipException correctly, fixes #355 Jul 28, 2018
jgiven-tests Removed usages of javax.xml.bind classes #324 Oct 8, 2017
scripts added publish gradle plugin to release Jul 28, 2018
.gitignore Upgrade Gradle to 4.5.1 Feb 16, 2018
.travis.yml travis: build with Java9 #324 Oct 8, 2017
AUTHORS Update AUTHORS Jul 9, 2015
CHANGELOG.md update changelog for v0.16.0 May 20, 2018
CONTRIBUTING.md Don't install PhantomJS using apt-get Apr 28, 2017
LICENSE added copyright to LICENSE Nov 6, 2014
README.md Fix the actual typo. May 16, 2018
build.gradle Add support for Spock. Jul 14, 2018
gradle.properties Update version to 0.16.0 May 20, 2018
gradlew upgrade to gradle 4.1 and junit5-M4 Aug 20, 2017
gradlew.bat Update the wrapper to Gradle 3.1 Oct 11, 2016
settings.gradle Add support for Spock. Jul 14, 2018
shippable.yml add shippable file Aug 19, 2014

README.md

Build Status Coverage Status Apache License 2.0 Maven Central Join the chat at https://gitter.im/TNG/JGiven Javadocs Open Source Helpers

JGiven

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.

Why another BDD tool?

Behavior-Driven Development (BDD) is a development method where business analysts, developers, and testers describe the behavior of a software product in a common language and notation. Behavior is typically described in terms of scenarios, which are written in the Given-When-Then notation. The common language and notation is one cornerstone of BDD. The other cornerstone is that the defined scenarios are executable, form a comprehensive test suite, and a living documentation for the software product.

In classical BDD tools for Java like JBehave or Cucumber scenarios are written in plain text files. This allows non-developers to write scenarios, because no programming knowledge is required. To make scenarios executable, developers write so-called step-implementations. To bind plain text to step implementations regular expressions are used. For developers maintaining these executable scenarios has a high overhead that is not required if tests would be directly written in a programming language.

Beside the classical BDD tools there are a number of tools for Java to write BDD tests in a programming language like Groovy (easyb) or Scala (ScalaTest). To our knowledge, however, there is no BDD tool where scenarios can be written in plain Java.

Finally, there are specification testing frameworks like Spock (Groovy) or LambdaBehave which are very developer-centric and good for unit-testing, but the generated reports are not in Given-When-Then form and are not easily readable by non-developers.

BDD with JGiven

  • Scenarios are written in standard Java code using a fluent, domain-specific API (no extra language like Scala or Groovy needed, no IDE plugin needed)
  • Java method names and parameters are parsed during test execution (no extra annotations needed)
  • Scenarios are executed by either JUnit or TestNG (no extra test runner needed)
  • Scenarios consist of so-called stages, which share state by injection, providing a modular way of writing Scenarios.
  • JGiven generates scenario reports for business owners and domain experts

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 pancake

In addition, you can generate a HTML Report.

Getting Started

  1. Start by reading the documentation section on JGiven's website.
  2. See the talk on JGiven held on the TNG Big TechDay

License

JGiven is published under the Apache License 2.0, see http://www.apache.org/licenses/LICENSE-2.0 for details.

Contributing

See CONTRIBUTING