Maven & Junit Theories - maven

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

Related

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

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.

Maven skip generating reports when executing Maven build

I have several reporting plugins defined in the project and when I do Maven → build fails with FileNotFoundException as the reports are cleared when I do Maven → clean. Is there a way to ignore reports when doing Maven build so that build passes without any issue? I tried using Surefire plugin but not luck.
My pom.xml looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>${maven-site-plugin.skip}</skip>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</reporting>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.2.0</version>
</dependency>
For maven-surefire
add after version
<configuration>
<skipTests>true</skipTests>
</configuration>
I got the fix for this now. I updated selenium version to 3.14 and I see no issue when building the project

Classpath issue with JUnit 4.12

I've got JUnit 4.12 in my pom and I keep getting the following:
[ERROR] org.apache.maven.surefire.util.SurefireReflectionException: java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Here is the surefire config:
The only thing that's fixed it is setting theadCount=0. This forces an isolated classloader, but if I force an isolated classloader through other settings but a threadCount>0 it fails again.
I've got hamcrest in my dependencies properly. Not sure where to go with this at this point.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>

No forking observed with surefire 2.16 despite forkCount being > 1

Here is my setting:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx256m</argLine>
</configuration>
</plugin>
And I'm using junit 4.12:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
But when launching my tests I can't see any forking going on?
I'm using maven 3.2.5 on linux with JDK 8.
I ran a little debug (mvn -X test) and it turns out that despite using version 4.12 surefire isn't using the junit47 provider, but the junit4 provider. Unfortunately the junit4 provider does not seem to handle forkCount.
Crawling through the documentation I could find the following algo that selects the provider : https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
The parallel attribute must be set in order to activate the junit47 provider (a little counter-intuitive...).
I've created a JIRA for that: https://issues.apache.org/jira/browse/SUREFIRE-1171
Now my config looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>1</threadCount>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx256m</argLine>
</configuration>
</plugin>
Edit
Turns out, redirectTestOutputToFile is now rendered useless... I've added a comment to an existing issue : https://issues.apache.org/jira/browse/SUREFIRE-703?focusedCommentId=14653289&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14653289
I came up with the following to have both forks and redirectTestOutputToFile work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<configuration>
<forkCount>1C</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reuseForks>true</reuseForks>
<argLine>-Xmx512m</argLine>
</configuration>
</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>

Resources