Maven Failsafe: Exclude tests which are part of a test suite - maven

I'm using Maven Failsafe to execute integration tests in my project. Therefore I include a class which uses the JUnit Suite feature.
Is it possible to exclude tests, which are included in the test suite, through the <excludes>?
Until now I tried to exclude them in that way:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M3</version>
</dependency>
</dependencies>
<executions>
<execution>
<configuration>
<!-- Some config done here -->
<includes>
<include>com.package.TestSuiteToInclude</include>
</includes>
<excludes>
<exclude>com.package.TestToExclude</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
But this did not work.
I would prefer to exclude them in the pom.xml rather than creating and maintaining another test suite without them.

Related

Get Arquillians Code Coverage Using JaCoCo

I have a Maven build that runs Arquillian tests on a Wildfly. What I want to do is run JaCoCo as well so that I get a test coverage.
What I did to my working Arquillian setup: I changed the parent's pom.xml the following way:
<properties>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<jacoco.out.ut.file>../target/jacoco/jacoco-ut.exec</jacoco.out.ut.file>
<jacoco.out.it.file>../target/jacoco/jacoco-it.exec</jacoco.out.it.file>
<sonar.jacoco.reportPaths>${jacoco.out.ut.file},${jacoco.out.it.file}</sonar.jacoco.reportPaths>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-ut-agent</id>
<phase>process-test-classes</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${jacoco.out.ut.file}</destFile>
<propertyName>jacoco.agent.ut.arg</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>prepare-it-agent</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${jacoco.out.it.file}</destFile>
<propertyName>jacoco.agent.it.arg</propertyName>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${test.argLine} ${jacoco.agent.it.arg}</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${test.argLine} ${jacoco.agent.ut.arg}</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
That's a setup that works in multiple other projects (without Arquillian), so I assume it must work now, too.
For the module hosting the integration project I added the following:
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>1.0.0.Alpha9</version>
<scope>test</scope>
</dependency>
</dependencies>
The maven-surefire-plugin is called there (which is weird to me, but I tried maven-failsafe-plugin and it didn't work either).
When executed the module produces a jacoco.exec (which is 70kb for only the one module, so at least not empty). Sonar uses these files in the report generation. Still the code coverage gets displayed as 0%.
I found a couple tutorials on this topic, but they all seem to be missing a step (at least the setup is always identical to mine).
How do I get Arquillian to use JaCoCo to report the code coverage?

Multiple test configurations for surefire plugin

I have an issue with my pom:
There are two types of tests running within the project:
Main set of tests using TestNG and JUnit code coverage tests. What I would like is to run JUnit tests on test-compile phase and do not run TestNG tests (which are run on test phase) if previous failed.
As of now I have the following which runs only TestNG:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.8.4/aspectjweaver-1.8.4.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>src/test/_all.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
I tried to play with <execution> tag but I can't provide path to TestNG suite then. Any ideas how to combine these tests using surefire plugin and specify different goals?
Solution was to add maven-failsafe-plugin separately from maven-surefire-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>junitcodecoverage/**Test.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>test-compile</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

Running single integration test through terminal [duplicate]

This question already has answers here:
How to run individual test in the integration-test target in maven
(9 answers)
Closed 8 years ago.
I have some integration tests in my project under src/test-integration/java.
I have no problem in running integration tests.
But how do i run a single integration test through Terminal?
When i use mvn integration-test -Darg1=data1 it runs all the integration tests.
I tried using mvn integration-test -Dagr1=data1 -Dtest=IntegrationTestClass1 but it did not work
Any solutions?
I am using maven-surefire-plugin-2.9 and maven-failsafe-plugin-2.6
Read this artice: Running a Single Test
Proper way to execute single integration test is to use property it.test
mvn -Dagr1=data1 -Dit.test=IntegrationTestClass1 verify
If this is not working then publish your pom.xml, because src/test-integration/java is not standard location for integrations test.
Standard location for all tests by conventions is src/test/java. All integration test by default should have suffix IT. This is default failsafe configuration for integration tests.
Below is my pom.xml, i can not chare my full pom because of some restrictions but this is the gist of it
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<configuration>
<skipTests>false</skipTests>
<failIfNoTests>false</failIfNoTests>
<includes>
<include>**/*.class</include>
</includes>
<excludedGroups>com.IntegrationTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<configuration>
<reuseForks>true</reuseForks>
<groups>com.IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skipITs>false</skipITs>
<skipTests>false</skipTests>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

maven-failsafe-plugin not seeing my tests (seleniumHQ)

i'm writing tests via selenium web driver here's my code :
Pom.xml
<project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
</dependency>
</dependencies>
<build>
<finalName>SeleniumebDriverProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My test class named GoogleTest.java.
after reading this post : failsafe plugin won't run on one project but will run on another -- why?
I changed the name of my class so it's:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
<executions>
</plugin>
But the problem persist.
The goal of the maven-failsafe-plugin is named integration-test instead of test. Furthermore if you changed your naming convention to the convention of maven-failsafe-plugin than you don't need any configuration which includes etc. files. Just use the defaults.
Furthermore i assume you have started running the integration tests via:
mvn verify

Maven & Junit Theories

I want to run JUnit Theories under Maven3,
The Theories have the Annotation #Theory before the method.
Running the Tests in Eclipse makes no problem.
Running it under Maven with the surfire Plugin I get "java.lang.Exception: No runnable methods"
How can I handle this Problem
It works for me. My configuration in plugin section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Junit*.java</include>
<include>**/*Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
<excludedGroups combine.self="override" />
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
I used junit version 4.10

Resources