MCPcopy Index your code
hub / github.com/TNG/JGiven

github.com/TNG/JGiven @v2.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.3 ↗ · + Follow
3,957 symbols 15,383 edges 677 files 326 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 8

License

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

Contributing

See CONTRIBUTING

Extension points exported contracts — how you extend this code

StepFunction (Interface)
A functional interface for defining ad-hoc steps. @see Stage#$(String, StepFunction) @param the stage in which [14 implementers]
jgiven-core/src/main/java/com/tngtech/jgiven/StepFunction.java
JGivenReport (Interface)
(no doc) [5 implementers]
jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/JGivenReport.java
Cook (Interface)
(no doc) [2 implementers]
jgiven-examples/src/test/java/com/tngtech/jgiven/examples/pancakes/app/Cook.java
CaseAsProvider (Interface)
Provides the description of a scenario case. @since 0.15.0 [8 implementers]
jgiven-core/src/main/java/com/tngtech/jgiven/annotation/CaseAsProvider.java
JGivenReportsContainer (Interface)
(no doc) [2 implementers]
jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/JGivenReportsContainer.java
AsProvider (Interface)
Provides a representation of a stage method, scenario or scenario class. @since 0.12.0 [9 implementers]
jgiven-core/src/main/java/com/tngtech/jgiven/annotation/AsProvider.java
JGivenTaskExtension (Interface)
(no doc)
jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/JGivenTaskExtension.java
StringConverter (Interface)
Interface to create converter function to specify the to map the incoming command line argument to the object See {@link [18 …
jgiven-core/src/main/java/com/tngtech/jgiven/report/config/converter/StringConverter.java

Core symbols most depended-on inside this repo

given
called by 394
jgiven-core/src/main/java/com/tngtech/jgiven/Stage.java
self
called by 335
jgiven-core/src/main/java/com/tngtech/jgiven/base/StageBase.java
and
called by 293
jgiven-core/src/main/java/com/tngtech/jgiven/Stage.java
when
called by 251
jgiven-core/src/main/java/com/tngtech/jgiven/Stage.java
then
called by 229
jgiven-core/src/main/java/com/tngtech/jgiven/Stage.java
get
called by 202
jgiven-core/src/main/java/com/tngtech/jgiven/impl/util/FieldCache.java
add
called by 180
jgiven-core/src/main/java/com/tngtech/jgiven/report/model/ReportStatistics.java
get
called by 116
jgiven-core/src/main/java/com/tngtech/jgiven/report/analysis/CaseDifferenceAnalyzer.java

Shape

Method 3,115
Class 791
Interface 36
Enum 15

Languages

Java100%
Kotlin1%

Modules by API surface

jgiven-junit/src/test/java/com/tngtech/jgiven/junit/ScenarioExecutionTest.java59 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioExecutor.java51 symbols
jgiven-tests/src/test/java/com/tngtech/jgiven/report/model/GivenReportModel.java50 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioModelBuilder.java45 symbols
jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioModelBuilderTest.java41 symbols
jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioExecutorTest.java41 symbols
jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java41 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/report/model/StepModel.java37 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/report/model/StepFormatter.java36 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/config/TagConfiguration.java36 symbols
jgiven-gradle-plugin/src/test/java/com/tngtech/jgiven/gradle/JGivenPluginTest.java35 symbols
jgiven-core/src/main/java/com/tngtech/jgiven/report/model/Tag.java34 symbols

For agents

$ claude mcp add JGiven \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact