Maven/Surefire not finding unit tests

后端 未结 2 518
醉话见心
醉话见心 2021-01-16 05:59

I tried creating a test project with maven and the unit testing worked fine. However, when trying to do the same for a j2ee project, the unit tests cannot be found by surefi

2条回答
  •  轮回少年
    2021-01-16 06:25

    As Cedric said above, Surefire has some problems with TestNG and JUnit tests in the same project. I found that when running "mvn test -X", Surefire was using the testng plugin instead of junit even though the actual test was a JUnit one.

    [DEBUG] Adding to surefire test classpath: C:\Users\Croydon.IVSTEL1\.m2\repository\org\apache\maven\surefire\surefire-testng\2.8\surefire-testng-2.8.jar Scope:test
    

    I checked the dependency hierarchy and didn't find any other plugin requiring testng. Then I found the spring testng dependency.

    
      org.apache.struts
      struts2-testng-plugin
      ${org.apache.struts.version}
      test
    
    

    After disabling it,

    [DEBUG] Adding to surefire test classpath: C:\Users\Croydon.IVSTEL1\.m2\repository\org\apache\maven\surefire\surefire-junit4\2.8\surefire-junit4-2.8.jar Scope: test
    

    Surefire uses the junit plugin and the tests are detected.

提交回复
热议问题