0

strong textI have a project that has both Junits and TestNG tests.

Some advised me to load the Junits from the TestNG configuration file as explained here: http://testng.org/doc/documentation-main.html#junit (and update the dependancies of testNG in the pom.xml accordingly), yet it doesn't work for me.

According to here: Maven does not find JUnit tests to run, mvn scans for tests according to the postfix of the class name in order to run junits (i.e. classes whose name ends with *test.java, tests.java etc.). The issue is that when TestNG is configured, the Junits don't run.

For that end, My question is:

can one explicitly ask maven to run certain Junits? And how would it still hold when TestNG is involved? (because there has been a disctussion that the two cannot run toghether here: http://jira.codehaus.org/browse/SUREFIRE-377 yet I guess it a bit out of date).

For that end, I an using mvn 2.2.1 (and not allowed to change the version :) )

testNg.xml file:

<suite name="VcopsCommonSuite" verbose="1">
  <test name="TestNG">
    <classes>
      <classes name="<some path>.<testNG: test class1>"/>
      <classes name="<some path>.<testNG: test class2>"/>
    </classes>
   </test>
<test name="JUnit" junit="true">
 <classes>
   <classes name="<some path>.<junit: test class1>"/>
  <classes name="<some path>.<junit: test class2>"/>
    </classes>
  </test>
</suite>

In my pom.xml file, the dependancy are configured as followed:

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8.1</version>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </exclusion>
  </exclusions>
</dependency>
Community
  • 1
  • 1
Maoritzio
  • 1,142
  • 2
  • 13
  • 31
  • First hint about [Maven 2.2.1](http://maven.apache.org/maven-2.x-eol.html) whoever is responsible for this update as soon as possible. Apart from that do you follow the naming conventions (*Test.java) etc. correctly located in `src/test/java` ? Furthermore i would suggest to decide to use either JUnit for unit testing or TestNG but not both. My recommendation is to use TestNG for integration tests etc. BTW: Can you show your pom file ? – khmarbaise Mar 23 '14 at 17:43
  • possible duplicate of [Run a single test method with maven](http://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven) – Joe Mar 25 '14 at 12:29
  • @khmarbaise - I did all the above but there was no change. Apparently the Maven version was too old and didn't support the functionality at all. – Maoritzio Mar 26 '14 at 12:41
  • 1
    @Joe - not a duplication. the refernced thread deals with running only junits. this one asks how to run them along with TestNg tests. – Maoritzio Mar 26 '14 at 12:44
  • @khmarbaise please don't pay attention to the above comment. xml files are added to the question. – Maoritzio Mar 26 '14 at 12:51
  • 1
    Why did you exlude junit from TestNG ? Maven 2.2.1 will work as well. The question is which maven-surefire-plugin version do you use? – khmarbaise Mar 26 '14 at 13:13

1 Answers1

0

It appears that the problem stems from the version of junit: mine was about ~3 and the required behavior is applicable from around version 4.7.

Just in case one comes across this thread, he\she can use the links mentioned in the main question and also use the following information: http://solidsoft.wordpress.com/2013/03/12/mixing-testng-and-junit-tests-in-one-maven-module-2013-edition/ http://executeautomation.com/blog/how-to-run-test-using-testng-in-selenium-2/ http://executeautomation.com/blog/how-to-configure-testng-with-testng-xml-2/

Another option is to configure the activation in the surefire maven plugin to run either Junits and testNG alternately.

Maoritzio
  • 1,142
  • 2
  • 13
  • 31