testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k stars 1.02k forks source link

[Maven-Surefire] Surefire runs JUnit tests ignore method filtering in case TestNG in classpath #982

Open baev opened 8 years ago

baev commented 8 years ago

In case TestNG in project classpath surefire-maven-plugin runs the JUnit tests ignore method name filtering.

There is a sample project to reproduce: https://github.com/baev/surefire-testng-junit-bug

Simply clone it and run mvn clean test -Dtest=MyTest#asdasdasd

There is no test named asdasdasd and there is no TestNG suites or tests. There is only the dependency in classpath.

TestNG 6.9.10 maven-surefire-plugin 2.19.1

See for more details https://issues.apache.org/jira/browse/SUREFIRE-1225?focusedCommentId=15141199&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15141199

Summon @tibor17

Tibor17 commented 8 years ago

Surefire is using the MethodSelector the same for option junit=true|false. These are our calls. As @baev found out the selector is not applied to JUnit if the option is set to true.

xmlTest.getMethodSelectors().add( selector ); ... testng.setXmlSuites( xmlSuites ); testng.run();

Tibor17 commented 8 years ago

I checked several versions and it looks like only class filter works.

juherr commented 8 years ago

Thanks for the report.

As I understand, XmlMethodSelector only accepts class: https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/xml/XmlMethodSelector.java#L18 But the TestNG CLI is able to filter methods: https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/TestNG.java#L521-L557

@Tibor17 Maybe Surefire can use XmlClass and XmlInclude instead of XmlMethodSelector. What do you think? If you want, I can try it.

Tibor17 commented 8 years ago

Hi @juherr , thx for fast reply. I appreciate if you make a try. It's TestNGDirectoryTestSuite class. The Parameterized is more complex runner, so I tried to test similar scenario mvn test -Dtest=MyTest2#testWithParameters with pure JUnit test class and two methods but still the bad result : either nothing to run or running both methods.

juherr commented 8 years ago

Well, forget what I said about XmlMethodSelector, I was wrong and I confirm it is a TestNG issue: IMethodSelector (first time I see it :p) is not used by JUnit runners.