JUnit tests pass in Eclipse but fail in Maven Surefire

前端 未结 17 1966
臣服心动
臣服心动 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条回答
  •  温柔的废话
    2020-11-29 17:41

    This doesn't exactly apply to your situation, but I had the same thing -- tests that would pass in Eclipse failed when the test goal from Maven was run.

    It turned out to be a test earlier in my suite, in a different package. This took me a week to solve!

    An earlier test was testing some Logback classes, and created a Logback context from a config file.

    The later test was testing a subclass of Spring's SimpleRestTemplate, and somehow, the earlier Logback context was held, with DEBUG on. This caused extra calls to be made in RestTemplate to log HttpStatus, etc.

    It's another thing to check if one ever gets into this situation. I fixed my problem by injecting some Mocks into my Logback test class, so that no real Logback contexts were created.

提交回复
热议问题