Maven separate Unit Test and Integration Tests

The solution is this: <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>${surefire.skip}</skip> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> … Read more

Strategy for debugging surefire “The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?”

Steps: (1) Run mvn with the -e and -X options to get more debug information. (2) Look for “Error” in the output. In my case, when I ran the mvn command, part of the output included: [ERROR] Command wascmd.exe /X /C “C:\dev\dev-tools\….. (3) Execute the problematic command directly in the command shell. In my case, … Read more

Maven (Surefire): copy test resources from src/test/java

bmargulies gave the answer, but let me fill in some details. <testresources> can be added to the <build> node of the project’s POM, like this: <testResources> <testResource> <directory>${project.basedir}/src/test/java</directory> </testResource> </testResources> That copies everything in src/test/java — including the .java source code, which we don’t want. It also (as bmargulies only hinted at) overrides and replaces … Read more

NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11

This blog helped fix the same problem for me: Mixing JUnit, Hamcrest and Mockito: Explaining java.lang.NoSuchMethodError: org/hamcrest/Matcher.describeMismatch Inside the dependencies for Mockito and Junit, the author added excludes: <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <exclusions> <exclusion> <artifactId>hamcrest-core</artifactId> <groupId>org.hamcrest</groupId> </exclusion> </exclusions> </dependency>

Maven not running JUnit 5 tests

According to the annotation (import org.junit.jupiter.api.Test), you are trying to run JUnit 5 tests with Maven. According to the documentation, you have to add this dependency: <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.3.1</version> <scope>test</scope> </dependency> Your version of Maven comes with a version of maven-surefire-plugin which does not support JUnit 5. You could update your Maven to the … Read more

Merging Integration and Unit test reports with JaCoCo

I recently implemented this: after some headaches and a lot of testing, I have a configuration that works beautifully. <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <executions> <execution> <id>pre-unit-test</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <execution> <id>pre-integration-test</id> <goals> <goal>prepare-agent-integration</goal> </goals> <configuration> <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile> <propertyName>testArgLine</propertyName> </configuration> </execution> <execution> <id>post-integration-test</id> <phase>post-integration-test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> </configuration> </execution> … Read more

Maven Surefire plugin “Error occured in starting fork, check output in log”

You need to setup surefire plugin to use <forkMode>once</forkMode> like this: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <skipTests>false</skipTests> <testFailureIgnore>true</testFailureIgnore> <forkMode>once</forkMode> </configuration> </plugin>

File not found.