Wiremock extension to inject server into JUnit5 tests
Switch branches/tags
Nothing to show
Clone or download
SourcePond and lanwen Refactored WiremockCustomizer to take a CustomizationContext as argum…
…ent (#7)

* Refactored WiremockCustomizer to take a CustomizationContext as argument
- Introduced a parameter class CustomizationContext which additionally provides ExtensionContext and ParameterContext objects. This allows to implement more sophisticated setup logic based on the execution context.
- Added WiremockCustomizer::customize(WireMockServer server, CustomizationContext ctx) as default method to keep backward compatibility.
- Made WiremockCustomizer::customize(WireMockServer server) also a default method. This is to make sure, that only the necessary "customize" method needs be implemented on a WiremockCustomizer implementation (see TicketEndpoint).
- Allow to throw an exception from WiremockCustomizer::customize
- Added Unit-Tests
- Updated dependencies and plugin versions where possible
- Bumped version to 2.0.0-SNAPSHOT because the interface change

* Fixed assertion

* Use NoopWiremockCustomizer to test default methods (code coverage)

* Pass correct replacement to exception message

* Simplified tests
- Use assertThrows where applicable
- Inlined Executable where necessary
- Simplified WiremockResolverUnitTest, removed tests which are already covered by integration test
Latest commit dbebebb May 2, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis misc Jun 13, 2017
src Refactored WiremockCustomizer to take a CustomizationContext as argum… May 2, 2018
.gitignore initial Jun 13, 2017
.travis.yml maven central deployment with travis Jun 13, 2017
LICENSE initial Jun 13, 2017
README.md update for Junit5 GA (#2) Sep 11, 2017
pom.xml Refactored WiremockCustomizer to take a CustomizationContext as argum… May 2, 2018

README.md

Wiremock JUnit5

codecov Maven Central

Simple extension to inject ready-to-use wiremock server to JUnit5 test

Start Guide

  1. Add dependency
ru.lanwen.wiremock:wiremock-junit5:${wiremock-junit5.version}
  1. Create JUnit5 test:
@ExtendWith({
        WiremockResolver.class,
        WiremockUriResolver.class
})
class WiremockJUnit5Test {

    @Test
    void shouldInjectWiremock(@Wiremock WireMockServer server, @WiremockUri String uri) {
        customize(server); // your setup
        SomeApiClient api = SomeApiClient.connect(uri);

        Response response = api.call();
        assertThat(response.headers(), hasSize(1));
    }
}

Reuse customization

With ru.lanwen.wiremock.config.WiremockCustomizer and ru.lanwen.wiremock.config.WiremockConfigFactory you can reuse logic of initial setup.

Please look into test for example.

Compatibility with JUnit5

  • v1.0.1 -> M4
  • v1.1.0 -> RC2
  • v1.1.1 -> GA