Since a while it is possible to configure maven surefire to execute jUnit tests and testNG tests in one build. I won't expand on the reasons why I'm doing that (ok, hint: testNG is our standard framework but some frameworks like jnario require jUnit).
The general way to do it is to configure the surefire plugin like this:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
This works quite well, jUnit tests and testNG tests get executed.
BUT – now I see that testNG tries to execute the jUnit tests too (and maybe vice-versa) – with no success, of course, because it won't see any of its annotations, but it looks like it re-marks the tests to "passed"… anyway, some reporting tools don't show test fails in jUnit tests anymore unless I comment the second dependency entry.
Is there any better way to configure surefire so that tests from both frameworks are executed ONLY by their test runners?
Best Answer
Had the same problem as you. Zero results in TestNG reports but looks like tests were runned. Finally get this work on two separate executions of
maven-surefire-plugin
dependencies
section from plugin.<testNGArtifactName>
(and we'll need it) tests will be executed by TestNG anyway and will fail onjava.lang.NullPointerException
TestNg
<executions>
like below:Tested with:
This configuration is the marge of ideas from:
Running TestNG-, JUnit3- and JUnit4-tests with Maven Surefire in one run,
your SUREFIRE bug report,
surefire plugin configuration
Hope it helps.