Coder Social home page Coder Social logo

jenspiegsa / wiremock-extension Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 7.0 40 KB

The wiremock-extension is a JUnit 5 extension that starts WireMock before running tests and stops it afterwards. It is similar to the WireMockRule for JUnit 4.

License: MIT License

Java 100.00%

wiremock-extension's Introduction

wiremock-extension

Build Status codecov Donate

The wiremock-extension is a JUnit 5 extension that starts WireMock before running tests and stops it afterwards. It is similar to the WireMockRule (docs) for JUnit 4.

Usage

Step 1. Add the JitPack repository to your pom.xml file

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the wiremock-extension dependency

<dependency>
    <groupId>com.github.JensPiegsa</groupId>
    <artifactId>wiremock-extension</artifactId>
    <version>0.4.0</version>
    <scope>test</scope>
</dependency>

Step 3. Annotate test classes by @ExtendWith(WireMockExtension.class)

  • see ExampleTest for further configuration and different use cases.

Contribute

Feedback is welcome. The source is available on Github. Please report any issues.

About

Plugin originally created by Jens Piegsa.

wiremock-extension's People

Contributors

anno1985 avatar celcius112 avatar jenspiegsa avatar thomasdarimont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wiremock-extension's Issues

Reusing server(s) between each test

Hi,

First of all, I would like to thank you for this extension. I really like this simple but expressive API :).

I have a suggestion for the extension lifecycle callback: I think creating and stopping server(s) for every test is unnecessarily costly. Was there a reason why you did it that way ?

One way would be to do like the WireMockClassRule rule:

  • Before each method, we check whether the server is running using the method WireMockServer#isRunning().
    - If it is running, reset the mappings on the server's client
    - If it is not running, start and configure it

Another solution would be to use JUnit 5's store, so that we can easily share server instances between tests (while not forgetting to reset the server(s) before or after each test).

With your current implementation it might require some refactoring. That's why I wanted to have your opinion before submitting a PR.

Thank you !

java.net.BindException: Address already in use error with some disabled tests

Hello,

First of all, thanks for this nice WireMockExtension, it's really appreciated.
I just get an error on the 0.3.1 version. When you have some disabled tests in a test class, it seems that the WireMockExtension start a server in the postProcessTestInstance but never stop it. So the other next tests just fail cause there is already a running server on this port. Obviously I have this issue cause I need to run my WireMock server on the same port for each test.
Let see this simple example to show the problem :

@ExtendWith(WireMockExtension.class)
class SimpleTest {
    @InjectServer
    private WireMockServer server;

    @ConfigureWireMock
    private final Options options = wireMockConfig();

    @Test
    void should_not_fail_test() {
        assertThat(server.isRunning()).isTrue(); // (1) OK
    }

    @Test
    @Disabled
    void should_not_fail_disabled_test() {
        assertThat(server.isRunning()).isTrue(); // (2) OK, disabled
    }

    @Test
    @Disabled
    void should_not_fail_another_disabled_test() {
        assertThat(server.isRunning()).isTrue(); // (3) Failed with Address already in use
    }
}

Thanks in advance.

the dependencies should be set to <scope>provided</scope>

I'm trying to use it in my junit 5 based app and getting version conflicts. I had to exclude below to make it work:

<exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.