JUnit 5 Extension: export random port as System property

599 views
Skip to first unread message

Ronny Bräunlich

unread,
Mar 18, 2022, 6:10:35 AM3/18/22
to wiremock-user
Hey everyone,

in some of my tests I use the @WireMockTest annotation and pass the port from the WireMockRuntimeInfo to the class being tested.
Nevertheless, this only works when I can pass in the port/url into the class. When using e.g. a SpringBootTest with Dependency Injection it's sometimes not possible.
Therefore, I wanted to ask here, what people think about exposing the (random) port as system property. So by using a well known property I'd be able to use it as a placeholder in my Spring test configuration. Basically, adding something like:
System.setProperty("wiremock.server.port", wireMockServer.port().toString())
to the WireMockExtension. Any opinions on this?

Cheers,
Ronny

Jamie Tanna

unread,
Mar 19, 2022, 3:54:22 AM3/19/22
to wiremock-user
I think that sounds like a reasonable request.

In the meantime, `WireMockRuntimeInfo wmRuntimeInfo` can be injected into a test method / `@ BeforeEach` so you could set a field / the property yourself.

Would you mind raising a feature request for it?

Cheers,
Jamie

Ronny Bräunlich

unread,
Mar 22, 2022, 1:25:39 AM3/22/22
to wiremock-user
Thank you for your feedback Jamie.
I opened the feature request:  Expose WireMock server port as system property · Issue #1841 · wiremock/wiremock (github.com)

Cheers,
Ronny
Reply all
Reply to author
Forward
0 new messages