JUnit tests pass in Eclipse but fail in Maven Surefire

前端 未结 17 1975
臣服心动
臣服心动 2020-11-29 17:28

I have written some JUnit tests using JUnit 4 and spring-test libraries. When I run the tests inside Eclipse then run fine and pass. But when I run them using Maven (during

17条回答
  •  萌比男神i
    2020-11-29 17:50

    Test execution result different from JUnit run and from maven install seems to be symptom for several problems.

    Disabling thread reusing test execution did also get rid of the symptom in our case, but the impression that the code was not thread-safe was still strong.

    In our case the difference was due to the presence of a bean that modified the test behaviour. Running just the JUnit test would result fine, but running the project install target would result in a failed test case. Since it was the test case under development, it was immediately suspicious.

    It resulted that another test case was instantiating a bean through Spring that would survive until the execution of the new test case. The bean presence was modifying the behaviour of some classes and producing the failed result.

    The solution in our case was getting rid of the bean, which was not needed in the first place (yet another prize from the copy+paste gun).

    I suggest everybody with this symptom to investigate what the root cause is. Disabling thread reuse in test execution might only hide it.

提交回复
热议问题