theangrydev / fluent-bdd

A BDD framework to help write tests in a fluent way, reusing givens, whens and thens.
Apache License 2.0
6 stars 1 forks source link
bdd fluent given junit tdd test then when yatpsec

Fluent BDD logo

Maven Central Javadoc Gitter

Build Status codecov Codacy Badge codebeat badge

Quality Gate

Example:

@RunWith(SpecRunner.class)
public class ExampleTest extends AcceptanceTest<TestResult> {

    private final GivenTheWeatherService theWeatherService = new GivenTheWeatherService(this, testInfrastructure);
    private final ThenTheAccessLogLinesContaining theAccessLogLines = new ThenTheAccessLogLinesContaining();
    private final ThenAssertion<ThenTheResponse, TestResult> theResponse = ThenTheResponse::new;
    private final ThenAssertion<ThenTheResponseHeaders, TestResult> theResponseHeaders = ThenTheResponseHeaders::new;
    private final WhenTheWeatherIsRequested theUser = new WhenTheWeatherIsRequested(testInfrastructure, "TheUser");
    private final ThenTheWeatherServiceWasCalled theWeatherServiceWasCalled = new ThenTheWeatherServiceWasCalled();

    @Test
    public void assertionTest() {
        given(theWeatherService.willReturn().weatherDescription("light rain").forCity("London"));
        when(theUser.requestsTheWeather().forCity("London"));
        then(theResponse).isEqualTo("There is light rain in London");
        and(theResponseHeaders).contains("Content-Length").contains("Date");
    }

    @Test
    public void assertionBuilderTest() {
        given(theWeatherService.willReturn().weatherDescription("light rain").forCity("London"));
        when(theUser.requestsTheWeather().forCity("London"));
        then(theAccessLogLines.containing("GET /weather")).hasSize(1);
    }

    @Test
    public void verificationTest() {
        given(theWeatherService.willReturn().weatherDescription("light rain").forCity("London"));
        when(theUser.requestsTheWeather().forCity("London"));
        then(theWeatherServiceWasCalled.withCity("London"));
    }
}

Dependency:

<dependency>
    <groupId>io.github.theangrydev.fluentbdd</groupId>
    <artifactId>all</artifactId>
    <version>8.2.2</version>
</dependency>

You can also depend on the modules core, assertj-extensions, hamcrest-extensions, mockito-extensions and yatspec-extensions separately if you don't need all of them.

Module Stability

Module Stability Comments
core Stable Used by a small Agile team on a daily basis since March 2016, contains the bulk of the Fluent BDD framework
yatspec-extensions Stable Used by a small Agile team on a daily basis since March 2016, lightweight module that pulls in the YatSpec dependency and provides some small integrations
assertj-extensions Experimental No real world users yet, added since AssertJ has lots of useful assertion methods that could come in handy
hamcrest-extensions Experimental No real world users yet, added since Hamcrest is a popular framework that users might already be invested in
mockito-extensions Experimental No real world users yet, developed as a curiosity to see how integration with Mockito could be possible

Releases

The versioning scheme follows Semantic Versioning 2.0.0, to help you identify non backwards-compatible changes when you are upgrading.

8.2.2

8.2.1

8.2.0

8.1.2

8.0.0

7.2.2

7.2.1

7.1.0

7.0.0

6.0.0

5.0.2

5.0.1

4.2.0

4.1.1

4.1.0

4.0.1

3.0.1

3.0.0

2.0.1

1.6.0

1.5.0

1.4.0

1.3.0

1.2.1

1.2.0

1.1.0

1.0.7

1.0.6

1.0.0