Seemingly Random Test Failure With Maven & Spring Boot 2 When A WebFluxTest Is Introduced

流过昼夜 提交于 2019-12-25 02:26:41

问题


Environment

  • OSX 10.13.5
  • Java 10.0.1 2018-04-17
  • Apache Maven 3.5.2
  • Spring Boot 2.0.3.RELEASE
  • Maven Surefire plugin 2.22.0

Issue

I have a test which reliably passes:

public class TransformerTest {

    private final MyTransformer transformer = new MyTransformerImpl();

    @Rule
    public final OutputCapture outputCapture = new OutputCapture();

    @Test
    public void successShouldLogSuccessMessages() {
        final B result = transformer.transform(new A());
        outputCapture.expect(containsString("First message"));
        outputCapture.expect(containsString("Second message"));
    }

}

The transformer uses log4j to log two lines via log.debug("First message") and log.debug("Second message"). I can run this test 1,000 times and it will pass.

When I introduce this test class

@WebFluxTest
@RunWith(SpringRunner.class)
public class DummyTest {

    @Autowired
    private WebTestClient client;

    @MockBean
    private MyService service;

    @Test
    public void dummyTest() {
        doRequest()
            .expectStatus().isAccepted()
            .expectBody().isEmpty();
    }

    private WebTestClient.ResponseSpec doRequest() {
        return client.post()
            .uri("/")
            .exchange();
    }
}

The new test reliably passes - however the first test (which is seemingly unrelated to this one) now fails only when the build is run with Maven.

  • Running the first test standalone via the IDE will yield a 100% reliable pass.
  • Running the entire test suite of the project in the IDE (not via Maven) also yields a 100% reliable pass.
  • Removing the second test results in the first passing again 100% reliably - and this is the only source code difference.

The failure message is:

TransformerTest.successShouldLogSuccessMessages Expected: (a string containing "First message" and a string containing "Second message") but: a string containing "First message" was ""

Does anyone know what might be going on? Is the first test already fundamentally flawed and the introduction of the second test is simply exposing this flaw or has the introduction of the second test fundamentally altered the behaviour of the test suite?

Configuration

My entire surefire configuration is:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <excludedGroups>com.example.IntegrationTest</excludedGroups>
            </configuration>
</plugin>

Neither of these tests are part of the integration test group. I have not modified the surefire defaults for parallelism or forking. Since this is just an issue I experience when running with Maven via surefire, is it possible that it's a race condition?

I can reproduce this issue with 100% reliability on more than one machine.

来源:https://stackoverflow.com/questions/51048684/seemingly-random-test-failure-with-maven-spring-boot-2-when-a-webfluxtest-is-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!