Question

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>
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top