Maven/Surefire not finding unit tests

落爺英雄遲暮 提交于 2019-12-01 12:04:27

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.

<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2-testng-plugin</artifactId>
  <version>${org.apache.struts.version}</version>
  <scope>test</scope>
</dependency>

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.

Surefire has a few problems when you tell it to run both TestNG and JUnit tests. There is a trick to make this work, though, but I can't remember what it is right now. Try to search around, you'll probably find the answer on SO somewhere.

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