-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@InjectWireMock not working in conjunction with Cucumber #73
Comments
I'm attaching the project files |
I think the problem here is that the Junit5-extension is not triggered. None of the functionality it provides is available. Not sure if that can, or should, be fixed here. But perhaps you only need the Spring features. Something like: public class ApplicationSteps {
@Value("${wiremock.server.port}")
private int wiremockPort;
@When("foo")
public void foo() {
WireMock.configureFor(wiremockPort);
WireMock.reset(); // Not sure where, or if, you want/need this.
// Configure with code maby?
WireMock.stubFor(get("/ping").willReturn(aResponse().withStatus(200)));
}
} And if you don't want to configure with code, it will still look for configuration as stated in the log:
|
Thanks for the quick feedback. I tried your suggestion @CucumberContextConfiguration
@EnableWireMock
@SpringBootTest
public class ApplicationSteps {
@Value("${wiremock.server.port}")
private int wiremockPort;
@When("foo")
public void foo() {
WireMock.reset();
WireMock.configureFor(wiremockPort);
// assertThat(wireMockServer).isNotNull();
}
} but I'm getting the following exception:
|
Put reset after configureFor. I updated my comment with that. |
This does seem to work. Thanks a lot! The issue can be closed. You might want to consider adding this to the documentation. |
I have a good workaround now, but I was wondering why don't you add the WireMockServer bean to the Spring context (just like you add those two properties), so that it can simply be injected via |
In an earlier revision of the readme: It says "does not pollute spring application context with extra beans". But I dont know exactly what the problem was, it seems intended. |
Proposal
I'm testing my spring boot application with Cucumber. Unfortunately, @InjectWireMock doesn't seem to be working in that case.
Reproduction steps
I have a feature file in src/test/resources/features
An application class in src/man/java:
A test class in src/test/java
And a steps class also in src/test/java:
The test fails since wireMockServer is null. I'm using Java 21 and the latest versions of Spring Boot (3.4.0), Cucumber (7.20.1) and WireMock Spring Boot (3.4.0).
References
No response
The text was updated successfully, but these errors were encountered: