Reputation: 4990
Small question regarding Maven and running unit test please.
I have a very basic Java SpringBoot project, with some unit tests.
I run the basic mvn clean install
very straightforward.
For some reason I do not understand, I am seeing all of my unit tests run twice.
one time here:
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ project ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running MyTest
and one time here:
[INFO] --- maven-surefire-plugin:2.22.2:test (integration-test) @ project ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running MyTest
And here is my maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<reportsDirectory>target/reports/junit</reportsDirectory>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
May I ask what did I do wrong, as I do not want unit tests to run twice.
Thank you
Upvotes: 2
Views: 1550
Reputation: 77187
The Surefire and Failsafe plugins are very similar, and the primary distinction is the phase that they run in. Generally, Surefire runs during the test
phase and Failsafe runs during the integration-test
phase. (The default configuration has them looking for slightly different test names, such as *Test
vs. *IT
, to know when to run each.)
You have explicitly told Surefire (the unit-test plugin) to run during integration testing. If you don't want this, simply remove the entire executions
stanza. I also strongly recommend against telling Maven not to fail when the tests fail, and changing the report directory is simply likely to confuse tools like CI that are looking in the default location. Best? Take out the plugin definition entirely and use the defaults.
Upvotes: 2