Skip to content

Conversation

@PhilHardwick
Copy link

Adds support for wiremock via testcontainers.

Provides properties:

  • wiremock.port
  • wiremock.host
  • wiremock.url

No current way to configure mappings or extra files on the container, that can be added in another PR.

@CLAassistant
Copy link

CLAassistant commented Jun 6, 2025

CLA assistant check
All committers have signed the CLA.

@graemerocher graemerocher requested a review from melix June 6, 2025 13:16
Copy link
Collaborator

@melix melix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. Would you mind explaining how you would use it in a test?

@PhilHardwick
Copy link
Author

PhilHardwick commented Jun 6, 2025

Sure I would use it like:

@MicronautTest
public class TestUsingWiremock {

    @Value("${wiremock.url}") // can just use the port here too
    String wiremockUrl;
    private WireMock wireMock;

    @BeforeEach
    void setUp() {
        URI uri = URI.create(wiremockUrl); // if using just the port this isn't needed
        // configure static access
        WireMock.configureFor(uri.getHost(), uri.getPort());
        // or an instance of the wiremock client
        wireMock = WireMock.create().port(uri.getPort()).build();
        wireMock.register(get(urlEqualTo("/health"))
                .willReturn(aResponse().withBody("ok").withStatus(200)));
    }
}

Does this need to be in the docs?

…es/wiremock/WiremockTestResourceProvider.java

Co-authored-by: Cédric Champeau <[email protected]>
@melix
Copy link
Collaborator

melix commented Jun 6, 2025

Not necessarily in the docs, I was thinking that it wouldn't be quite useful without mappings, but since I'm not familiar with Wiremock, I see from your example that this can be configured "externally" somehow.

@PhilHardwick
Copy link
Author

PhilHardwick commented Jun 6, 2025

yeah mappings are like static requests and responses in files. I mainly use Wiremock through the client and configure the requests and responses in the test that needs it.

To be honest I'm not sure how the mappings stuff would work with the files and the classpath, especially since test resources is in a separate process. I imagine it would need to be in src/testResources/resources

@melix
Copy link
Collaborator

melix commented Jun 6, 2025

To be honest I'm not sure how the mappings stuff would work with the files and the classpath, especially since test resources is in a separate process. I imagine it would need to be in src/testResources/resources

Either that, or you would have to add a dependency on the test resources classpath which contains your mappings. But I think it's useful to support this.

@sdelamo
Copy link
Contributor

sdelamo commented Jun 20, 2025

we have a tutorial with Wiremock. it would be used to try to re-write that sample app using this test resources integration instead. https://guides.micronaut.io/latest/testing-rest-api-integrations-using-mockserver.html

@sdelamo sdelamo moved this to In Progress in 4.10.0 Release Jun 20, 2025
@sdelamo sdelamo removed this from 4.10.0 Release Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants