@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 | 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 |
The versioning scheme follows Semantic Versioning 2.0.0, to help you identify non backwards-compatible changes when you are upgrading.
fluent-mockito
modulehamcrest-extensions
that acts as a bridge for using Hamcrest matchers as then
assertionsall
module with links to javadoc of the other modulesWithFluentAssertJ<TestResult>
extend WithFluentBdd<TestResult>
and calling recordThen
in each then
and and
method. This change is not backwards compatibleyatspec-zohhak-plugin
as test
scope not compile
scopeassertj-extensions
delegates to the WithAssertions
AssertJ convenience methodsassertj-extensions-generator
, that produces a plugin that is used to generate the source code for assertj-extensions
all
convenience dependency that pulls in all the other modulesWith*
interfacesmockito-extensions
that integrates with Mockito@Rule
FluentMockito
to use in conjunction with FluentBdd
, along with WithFluentMockito
groupId
is now io.github.theangrydev.fluentbdd
and the artifactId
is core
and yatspec-extensions
io.github.theangrydev.fluentbdd.core
and io.github.theangrydev.fluentbdd.yatspec
YatspecFluent
class was renamed to FluentYatspec
, similarly WithYatspecFluent
was renamed to WithFluentYatspec
FluentBdd
class that does not require yatspec at all, with a corresponding WithFluentBdd
interface FluentTest
to YatspecFluent
. This change is not backwards compatibleYatspecFluent
as a JUnit @Rule
alongside a WithYatspecFluent
interface for the BDD methods if you do not want to extend YatspecFluent
as the base class for your tests ThenAssertion
instances have been reused. Also relaxed all the instance checks to classes that appear to be mutable (have at least one instance field)Given
instance is not used more than once. This is to make it harder to accidentally share state by using the same builder style instance more than once. Similarly for ThenVerification
then
methods. ThenAssertion
is used for chained assertions. ThenVerification
is used for a blob verification that is built up. See the ExampleTest
for example usage. This change is not backwards compatible since Then
was renamed to ThenAssertion
FluentTest
methods public. Protected was enough, but it's clearer that they are part of the public API if they are publicInterestingGivens
and CapturedInputAndOutputs
fields. The TestState
can be accessed via the interface WithTestState
if it is really needed. This change is not backwards compatible since the fields were visible to subclasses of FluentTest
Request
from When
. This change is not backwards compatibleGiven
as a @FunctionalInterface
since it has a single abstract methodand
. Now you are free to use and
and given
and and
and then
interchangeably, so long as the first given
is a given
not an and
and the first then
is a then
not an and
ReadOnlyTestItems
to WriteOnlyTestItems