maven-failsafe-plugin is not executing my integration tests - maven

Bellow a part of my actual pom.
Testng tests for integration tests have been assigned a "integration" group in the #Test annotations.
To do little test I did not exclude the "integration" group during the test phase.
When building using for example mvn verify or mvn install the integration tests get executed in the test phase, but not the verify or integration-test phase.
The number of tests run remains 0. Somehow they are not picked up. Anyone have an idea on what might be wrong?
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.1</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
</executions>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</plugin>
Update: Adding TestNG as a dependency to the failsafe plugin does not
help

maven-failsafe-plugin by default includes only files matching following patterns:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
How did you name your test class(es)?

Related

Running spock integrations tests in its own folder in maven

I am trying to only run integration tests in maven with mvn. I have my tests in src/it/java for java integration tests and src/it/groovy for Spock integration tests. When I run mvn failsafe:integration-test, only the java integration tests in src/it/java are run.
This is my pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
<source>src/it/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<testSourceDirectory>src/it/groovy</testSourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<configuration>
<testSources>
<testSource>
<directory>src/it/groovy</directory>
<includes>
<include>**/*IT.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
<executions>
<execution>
<id>groovy-compile</id>
<goals>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
Any idea what I am missing here?
It looks like the issue is that your running only failsafe:integration-test. I am able to run groovy and java tests using the command:
mvn verify
In the failsafe docs it suggests to use the verify phase here - http://maven.apache.org/surefire/maven-failsafe-plugin/index.html
If mvn verify still doesn't run your groovy tests, check your_project/target/test-classes/path_to_your_test for expected class files and make sure that lines up with the includes option in the pom.

How to separate Unit Tests and Integration Tests for different levels of maven lifecycle

Here is my plugin configuration from pom.xml file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>run-unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<skipITs>true</skipITs>
<skipUTs>false</skipUTs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>run-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<skipITs>false</skipITs>
<skipUTs>false</skipUTs>
</configuration>
</plugin>
I have 2 test classes HelloTest.java and WorldITest.java.
When I run mvn clean test i want it to execute only HelloTest. But when i execute mvn clean integration-test, then I want both HelloTest and WorldITest to be executed.
But the problem is that it executes the Integration test also in mvn clean test command.
PS: Original code was taken from the discussion : Prevent unit tests in maven but allow integration tests

How does Sonar Maven Plugin orchestrate tests?

Is it possible to configure how the surefire plugin is called when used with mvn sonar:sonar post compile.
In my maven project I have multiple test executions, for example
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.3</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
<parallel>methods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</execution>
<execution>
<id>default-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
<parallel>classes</parallel>
<argLine>${jacoco.agent.argLineIntegration}</argLine>
</configuration>
</execution>
</executions>
</plugin>
Note the integration tests in particular require some preprocessing ( aspectj compile for example ).
Is there any way to tell sonar to do this ? Or Indeed is it possible to generate the reports beforehand and just tell sonar to use them ?
You can have a look at the reuse report mode: http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project

Running JUnit test suite using Maven

I have written a JUnit test suite for running multiple test cases.
Now I want to run my test suite class (AllTest.java) at once so that all tests are triggered, carried and managed by one class. I know maven-failsafe-plugin is available, but is there any other easier way to invoke a JUnit test suite from Maven?
I dont want to use another plugin for this.
This is my current maven-failsafe-plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>**/AllTests.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
You can run it with -Dit.test=[package].AllTest (-Dtest with surefire), or configure the included tests in the pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>AllTest.java</include>
</includes>
</configuration>
</plugin>
You can run test suite using following maven command:
mvn test -Dtest=x.y.z.MyTestSuite
Note : x.y.z is the package name.

How do I configure when cobertura tests run in maven-cobertura-plugin?

In order to fine-tune which tests are run at which times and in which environments, we have several executions set up for the maven-surefire-plugin. We set the default configuration to skip all tests, then enable them for the executions we want. This by itself works well for us.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTests.java</exclude>
</excludes>
</configuration>
<execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
</configuration>
<execution>
</executions>
</plugin>
When I add the maven-cobertura-plugin to the mix, I run into problems. The cobertura goal runs, and successfully instruments my classes. However, no tests get run. I assume this is because the test execution that cobertura is running in is one that is skipped. However, I cannot find how to specify which phase and goal to set up for this execution. When I turn on all tests, the output seems to indicate that these are still running in these unit-tests and integration-tests phases/goals.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
How do I need to specify a surefire execution so that the cobertura will run it against the instrumented classes?
You will note from the docs that cobertura:cobertura
Must be wired as a report
Instruments, tests and generates a report
Runs in its own lifecycle cobertura (not the default lifecycle)
Invokes lifecycle phase test before running itself
So, wiring it accordingly should automatically result in instrumentation and testing.

Resources