Skip to content

@InjectWireMock not working in conjunction with Cucumber #73

Closed
@toellrich

Description

@toellrich

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

Feature: Foo
  Scenario: Foo
    When foo

An application class in src/man/java:

package test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

A test class in src/test/java

package test;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "test")
public class ApplicationTest {
}

And a steps class also in src/test/java:

package test;

import static org.assertj.core.api.Assertions.assertThat;

import com.github.tomakehurst.wiremock.WireMockServer;
import io.cucumber.java.en.When;
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.wiremock.spring.EnableWireMock;
import org.wiremock.spring.InjectWireMock;

@CucumberContextConfiguration
@EnableWireMock
@SpringBootTest
public class ApplicationSteps {

  @InjectWireMock
  private WireMockServer wireMockServer;

  @When("foo")
  public void foo() {
    assertThat(wireMockServer).isNotNull();
  }
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions