JUnit tests pass in Eclipse but fail in Maven Surefire

前端 未结 17 1961
臣服心动
臣服心动 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:55

    I had the same problem (JUnit tests failed in Maven Surefire but passed in Eclipse) and managed to solve it by setting forkMode to always in the maven surefire configuration in pom.xml:

    
        org.apache.maven.plugins
        maven-surefire-plugin
        2.12
        
            always
        
    
    

    Surefire parameters: http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html

    Edit (January 2014):

    As Peter Perháč pointed out, the forkMode parameter is deprecated since Surefire 2.14. Beginning from Surefire 2.14 use this instead:

    
        org.apache.maven.plugins
        maven-surefire-plugin
        2.16
        
            false
            1
        
    
    

    For more information see Fork Options and Parallel Test Execution

提交回复
热议问题