mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.6k stars 1.07k forks source link

Using @MockServerSettings on abstract class #781

Closed Aloren closed 4 years ago

Aloren commented 4 years ago

Describe the issue When @MockServerSettings is placed over abstract parent class, it is not picked up.

What you are trying to do We have a bunch of tests with common setup logic that is extracted to base parent test class and would like to reuse @MockServerSettings configuration for all of them.

MockServer version 5.10

To Reproduce

import org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.junit.jupiter.MockServerExtension;
import org.mockserver.junit.jupiter.MockServerSettings;

@MockServerSettings(ports = 6767)
@ExtendWith(MockServerExtension.class)
public abstract class BaseTest {
}
import org.junit.jupiter.api.Test;
import org.mockserver.client.MockServerClient;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;

public class Test1 extends BaseTest {

    private final MockServerClient client;

    public Test1(MockServerClient client) {
        this.client = client;
    }

    @Test
    void my_test() {
        client.when(HttpRequest.request().withPath("/any"))
                .respond(HttpResponse.response().withStatusCode(200));
    }
}

Expected behaviour @MockServerSettings is picked up from parent class.

MockServer Log

2020-05-14 14:42:21 INFO  MockServerEventLog:105 - started on port: 61862
jamesdbloom commented 4 years ago

This is now fixed and is in the SNAPSHOT build.