• Stars
    star
    438
  • Rank 99,453 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 4 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Behavior-Driven Development in plain Java

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 an 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 https://www.apache.org/licenses/LICENSE-2.0 for details.

Contributing

See CONTRIBUTING

More Repositories

1

ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
Java
3,181
star
2

ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
C#
899
star
3

boost-python-examples

Some examples for the use of boost::python
C++
837
star
4

ArchUnit-Examples

Examples for ArchUnit (A Java architecture test library, to specify and assert architecture rules in plain Java)
Java
544
star
5

junit-dataprovider

A TestNG like dataprovider runner for JUnit with many additional features
Java
246
star
6

keycloak-mock

A Java library to test REST endpoints secured by Keycloak via OpenID connect.
Java
122
star
7

virtual-office

Virtual Office gives you transparency on what Zoom.us rooms are currently occupied and who is present
TypeScript
122
star
8

ngqp

Declaratively synchronize form controls with the URL
TypeScript
81
star
9

please-cli

An AI helper for creating CLI commands
Shell
66
star
10

elevation-of-privilege

An online multiplayer version of the threat modeling card games: Elevation of Privilege (EoP), OWASP Cornucopia, OWASP Cumulus, and Elevation of MLsec.
TypeScript
55
star
11

next-generation-scrum-poker

Prototype for a new Scrum Poker
TypeScript
49
star
12

cumulus

Cumulus. Threat modeling the Clouds.
TeX
30
star
13

ApiCenter

A repository for all your API specifications
TypeScript
25
star
14

momo-scheduler

A scheduler that persists jobs in MongoDB
TypeScript
19
star
15

gs-rs

Rust
17
star
16

svnfiltereddump

A tool to extract parts from Subversion repositories
Python
14
star
17

flink-connector-email

IMAP / SMTP connectors for Apache Flinkยฎ
Java
13
star
18

ngx-structurals

Structural utility directives for Angular
TypeScript
13
star
19

jgiven-intellij-plugin

IntelliJ Plugin for JGiven
Kotlin
13
star
20

mustard-cli

A command line interface for bitbucket to review, comment and approve pull requests
C++
12
star
21

sinon-helpers

Create easily configurable sinon stubs that mimic constructors and keep track of their instances
JavaScript
12
star
22

jiradeps

Graphically assess the dependencies of your Jira stories
Python
7
star
23

please-pwsh

An AI helper for creating CLI commands in Powershell
PowerShell
7
star
24

property-loader

Original PropertyLoader reworked
Java
7
star
25

openpgp-validation-server

Automated Validation of OpenPGP Keys
Go
7
star
26

value-provider

Java
5
star
27

rest-demo-jersey

Spring-boot and Jersey based REST service showing the integration of rest-schemagen.
Java
4
star
28

NextGenerationTranslatorBackend

A translation backend for AI translation models
Python
4
star
29

if-webpage-plugins

Impact Framework Plugins for Webpage Measurement (CommonJS)
TypeScript
3
star
30

java-virtual-thread-benchmark

A simple benchmark to compare the performance of Java Virtual Threads, Java Threads and Reactor Core, based on scenarios with jdbc and hibernate. This is the support repo for the Melbourne Java & JVM users group event.
Java
2
star
31

homebrew-please

A Homebrew tap for the Please CLI
Ruby
2
star
32

apt-please

2
star
33

karma-child-process

JavaScript
2
star
34

xtab-converter

Convert existing dbunit XLS files to XML data sets
Java
1
star
35

TNG

1
star
36

SnapToJsClipper

JavaScript
1
star