I have cucumber framework and the following pom
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>CucumberE2ETest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
After I run my tests, I get this
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
As you can see the Tests run are 0.
The tests run fine from IntelliJ but maven does not run the tests.
My apologies for the large amount of copy-pasted content, but I want to provide as much information as possible because I'm not sure what to try next.
You're using cucumber-junit which integrates with JUnit 4. However because you're using JUnit 5, Surefire will not run JUnit 4 tests. You need to add the JUnit Vintage engine or Cucumber's JUnit 5 integration.
See for a working example:
https://github.com/cucumber/cucumber-java-skeleton
Related
When I run my test in Maven I get this:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
My test class, JsonReaderTest.class, is placed in src/test/java and follows the correct name convention as far as I know from maven-surefire-plugin.
Tests run fine when run outside of Maven.
I have this plugin included in my pom:
<!-- Executes tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
and this in my dependencies:
<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0</version>
</dependency>
and my test class:
package org.avalin.optaplanner.test.java;
import org.avalin.optaplanner.json.JsonReader;
import org.junit.jupiter.api.*;
import java.io.FileNotFoundException;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.*;
public class JsonReaderTest
{
#Test
#DisplayName("Test: No such file at designated path")
void testloadFromJsonTest() throws Exception
{
Throwable exception = assertThrows(FileNotFoundException.class,
()-> JsonReader.loadFromJson(".json"));
assertEquals(".json (No such file or directory)",
exception.getMessage());
}
#Test
#DisplayName("Test: Load Shifts from JSON (String instead of number)")
void testLoadShiftsFromJson3()
{
Throwable exception = assertThrows(NumberFormatException.class, ()-> JsonReader.loadFromJson(Paths.get("src/main/resources/org/avalin/optaplanner/json/faultyShift-2.json").toAbsolutePath().toString()));
assertEquals("\nOne or more of your \"shift\" elements has a number format exception.\n" +
"Check for errors in your JSON-properties.\n" +
"(Did you insert a string instead of a number in id?)",
exception.getMessage());
}
#Test
#DisplayName("Test: JSON is correctly loaded")
void testJsonIsLoaded()
{
assertFalse(JsonReader.jsonIsLoaded());
}
#AfterEach
void cleanJsonReader()
{
JsonReader.cleanJsonReader();
}
}
When I tried googling this problem, it seemed the only thing that could be wrong would be naming convention (class had to end with or start with test, I tested both with no change) and that the test class should be put into the appropriate folder.
When I run: mvn -Dtest=JsonReaderTest test
I get following:
Failed to execute goal org.apache.maven.plugins:maven-surefire-
plugin:2.20.1:test (default-test) on project optaplanner: No tests were
executed!
The JsonReaderTest.class is also correctly generated inside target/test-classes
What could be the culprit here?
Using the Maven Surefire plugin and JUnit 5 together requires some tweaking ...
From the docs:
The JUnit team has developed a very basic provider for Maven Surefire that lets you run JUnit 4 and JUnit Jupiter tests via mvn test. The pom.xml file in the junit5-maven-consumer project demonstrates how to use it and can serve as a starting point.
Due to a memory leak in Surefire 2.20, the junit-platform-surefire-provider currently only works with Surefire 2.19.1.
...
<build>
<plugins>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
This plugin worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-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>
</plugin>
Taken from https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
the following pom configuration worked for me:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
....
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
...
the plugin part as #glytching stated above
I was having the same problem. All the test classes were package private and JUnit 5 couldn't see them. The solution was to add this dependency to the pom file:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
I had the same issue, it took me days to find the solution!
First, make sure you end your class-name with ***Test.java, for example: MyGreatTest.java
Secondly, make your class and methods public! This is very important, otherwise mvn test will ignore your test class!
Thirdly, I added this peace of code in the pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
along with all junit dependencies like engine, api, launcher this one integrated all I guess
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.9.0-M1</version>
<scope>test</scope>
with latest version of surefire plugin
and it works solely as well for me without other junite dependencies
I'm trying to create a maven plugin for the first time.
everything works till now except for the testing part.
I want to write some test cases before I start at coding the plugin itself.
I've had really much trouble till now with being able to simply run a test case that doesn't even do anything itself.
I think I'm missing a dependency or that I'm using compatible versions. I've messed much with the versions and the exceptions have changed a lot. But this one keeps coming back.
So when I run mvn test I get the following response from the console:
λ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Simple Web Share Plugin 1.2.9-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # sws-maven-plugin ---
[INFO] Using '' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory maven-sws-plugin\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) # sws-maven-plugin ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to maven-sws-plugin\target\classes
[INFO]
[INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) # sws-maven-plugin ---
[INFO] Using '' encoding to read mojo metadata.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: java-annotations
[INFO] Mojo extractor for language: java-annotations found 1 mojo descriptors.
[INFO]
[INFO] --- maven-plugin-plugin:3.2:descriptor (mojo-descriptor) # sws-maven-plugin ---
[INFO] Using '' encoding to read mojo metadata.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: java-annotations
[INFO] Mojo extractor for language: java-annotations found 1 mojo descriptors.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # sws-maven-plugin ---
[INFO] Using '' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) # sws-maven-plugin ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # sws-maven-plugin ---
[INFO] Surefire report directory: maven-sws-plugin\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running plugins.MojoTest
org.codehaus.plexus.PlexusContainerException: Cycle detected in component graph in the system:
at org.codehaus.plexus.DefaultPlexusContainer.initialize(DefaultPlexusContainer.java:624)
at org.codehaus.plexus.DefaultPlexusContainer.construct(DefaultPlexusContainer.java:281)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:172)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:159)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:179)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:107)
at nl.ciber.maven.plugins.MojoTest.setUp(MojoTest.java:11)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException: Cyclic requirement detected
at org.codehaus.plexus.component.composition.DefaultCompositionResolver.addComponentDescriptor(DefaultCompositionResolver.java:65)
at org.codehaus.plexus.component.repository.DefaultComponentRepository.addComponentDescriptor(DefaultComponentRepository.java:229)
at org.codehaus.plexus.DefaultComponentRegistry.addComponentDescriptor(DefaultComponentRegistry.java:126)
at org.codehaus.plexus.DefaultPlexusContainer.addComponentDescriptor(DefaultPlexusContainer.java:514)
at org.codehaus.plexus.DefaultPlexusContainer.discoverComponents(DefaultPlexusContainer.java:969)
at org.codehaus.plexus.DefaultPlexusContainer.discoverComponents(DefaultPlexusContainer.java:941)
at org.codehaus.plexus.DefaultPlexusContainer.initialize(DefaultPlexusContainer.java:560)
... 29 more
Caused by: org.codehaus.plexus.util.dag.CycleDetectedException: Edge between 'Vertex{label='org.apache.maven.plugin.version.PluginVersionResolver:default'}' and 'Vertex{label='org.apache.maven.plugin.MavenPluginManager:default'}' introduces to cycle in the graph org.apache.maven.plugin.MavenPluginManager:default --> org.apache.maven.plugin.version.PluginVersionResolver:default --> org.apache.maven.plugin.MavenPluginManager:default
at org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:143)
at org.codehaus.plexus.util.dag.DAG.addEdge(DAG.java:123)
at org.codehaus.plexus.component.composition.DefaultCompositionResolver.addComponentDescriptor(DefaultCompositionResolver.java:60)
... 35 more
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.726 sec <<< FAILURE!
testFilePath(***.maven.plugins.MojoTest) Time elapsed: 0.686 sec <<< FAILURE!
junit.framework.AssertionFailedError: Failed to create plexus container.
at junit.framework.Assert.fail(Assert.java:47)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:164)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:179)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:107)
at ***.maven.plugins.MojoTest.setUp(MojoTest.java:11)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:95)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:121)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Failed tests: testFilePath(***.maven.plugins.MojoTest): Failed to create plexus container.
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.595 s
[INFO] Finished at: 2017-03-24T10:35:35+01:00
[INFO] Final Memory: 32M/497M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project sws-maven-plugin: There are test failures.
[ERROR]
[ERROR] Please refer to maven-sws-plugin\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
My POM.xml (I've added a few things what are proberally not needed, I've googled a lot and nothing worked till now):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***.maven.plugin.sws</groupId>
<artifactId>sws-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.2.9-SNAPSHOT</version>
<name>Simple Web Share Plugin</name>
<properties>
<project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
<maven.version>3.5.0-alpha-1</maven.version>
</properties>
<repositories>
<repository>
<id>mavencentral</id>
<name>Maven Central</name>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>org.fusesource.fabric</groupId>
<artifactId>fabric-maven-proxy</artifactId>
<version>7.0.1.fuse-084</version>
</dependency>
<dependency>
<groupId>***.webshare</groupId>
<artifactId>simple-web-share-api</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<!--<version>1.5.5</version>-->
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.5.0-alpha-1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
My POM for testing:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***.maven.plugins</groupId>
<artifactId>sws-maven-plugin</artifactId>
<packaging>jar</packaging>
<version>1.9.2-SNAPSHOT</version>
<name>reminder-maven-plugin Maven Mojo</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>***.maven.plugins</groupId>
<artifactId>sws-maven-plugin</artifactId>
<configuration>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
TestCase:
package ***.maven.plugins;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
/**
* Created by casper.hollemans on 20-3-2017.
*/
public class MojoTest extends AbstractMojoTestCase {
public void setUp() throws Exception {
super.setUp();
}
public void tearDown() throws Exception {
super.tearDown();
}
public void testFilePath() throws Exception {
}
}
So after struggling a bit more, I've been able to fix the exceptions.
The main problem wat that my POM was growing a bit big full of unnecessary dependencies. I've looked into the git of the maven clean plugin and compared my pom with the pom of the clean plugin. The main issue was, as I expected; I used the wrong versions. I'll post my current pom over here and the link to the maven plugin's git.
Maven plugins github page
Maven clean plugin (project I used to compare to).
My pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***.maven.plugin.sws</groupId>
<artifactId>sws-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.2.9-SNAPSHOT</version>
<name>Simple Web Share Plugin</name>
<properties>
<project.build.sourceEncoding>****</project.build.sourceEncoding>
<maven.version>3.0</maven.version>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<forkMode>never</forkMode>
</configuration>
</plugin>
</plugins>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>***.webshare</groupId>
<artifactId>simple-web-share-api</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
This question already has answers here:
Surefire is not picking up Junit 5 tests
(19 answers)
Closed 6 years ago.
Maven execution
mvn clean test
I am trying to use junit5 for one of my maven projects but not able to execute the unit tests during the test phase using -
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
The output that I get is -
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) # utils ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Tried implementing the solution mentioned # Surefire is not picking up Junit 5 tests to update the dependencies to -
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-api</artifactId>
<version>5.0.0-ALPHA</version><!--https://mvnrepository.com/artifact/org.junit/junit5-api -->
<scope>test</scope>
</dependency>
and updating the plugin to -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>surefire-junit5</artifactId>
<version>5.0.0-ALPHA</version><!--couldn't find this on the central though-->
</dependency>
</dependencies>
</plugin>
but the output remains same.
Question - Is this custom provider no more supported or is there any solution to executing the tests using maven, junit5 and/or junit5-api currently?
Note - The test execution was working fine with JUnit-4.
You should configure the maven-surefire-plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
You only need to include the junit-jupiter-api artifact and only in test scope in your dependencies section:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M3</version>
<scope>test</scope>
</dependency>
Please see http://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven for more information.
Edit - From the same docs.
In order to have Maven Surefire run any tests at all, a TestEngine
implementation must be added to the runtime classpath.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
I have a rest Spring Boot REST API that I want to test. I can run the tests manually in Eclipse (without maven and by running the application as JUnit test) and it runs fine and displays the results, but mvn test does not "work" as you will find out below.
Here is my POM file:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>org.demo</groupId>
<artifactId>rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>UserRegistrationServices</name>
<description>RESTful API</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- To deploy to external servlet container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- For Spring Boot testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>
<!-- For returning objects as JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>jackson-xml-databind</artifactId>
<version>0.6.2</version>
</dependency>
<!-- To decode Base64 data -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This is the result of mvn test:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building UserRegistrationServices 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to C:\Users\pmandayam\git\UserRegistrationServices\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\pmandayam\git\UserRegistrationServices\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\pmandayam\git\UserRegistrationServices\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # rest ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.768 s
[INFO] Finished at: 2015-07-28T12:07:41-05:00
[INFO] Final Memory: 24M/212M
[INFO] ------------------------------------------------------------------------
Here is a segment of my TestController.java class in src/test/java:
#Test
public void f_findByUsername() {
// Finding user with username 'user1username'
given().auth().basic("User1username", "Testpassword").when().get(
"http://localhost:8080/users/get/ByUsername?username=User1username")
.then().assertThat().body("username", is("User1username"));
}
At the top of the TestController class I have these annotations:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = Application.class)
#WebAppConfiguration
/* Tells the embedded Tomcat server to start on a random, open port */
#IntegrationTest("server.port:0")
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestController {....}
I'm not sure whats wrong. I don't have the surefire plugin but its looking for that it seems.
The code in the class you named TestController isn't a controller, it's a test, but the convention says that it's a controller (perhaps used in testing). By default, Surefire will be looking for tests matching *Test; rename the class to ControllerTest.
Use the below maven jar. It fixed my issue.
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
try checking if you are using the correct package for #Test annotation. In Spring Boot 2.3.6 is org.junit.jupiter.api.Test
Even if this is not recommended (as not standard), you can configure the maven surefire plugin too, as follows:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
Edit: Wildcard added before /Test*.java
As this question populates first on search engines I thought it would be helpful for the people looking for the solution for the wired behavior of SpringBoot from version 2.4 onwards.
Problem - When you migrate your SpringBoot project from older version to newer like 2.5.x then the existing junit test cases are ignored by maven.
Reason - SpringBoot has been migrated to junit5 and thats why maven is ignoring junit4 test cases. To see detailed test dependencies explore the pom for spring-boot-starter-test.
Solution 1 - Either you write your test cases in junit5 with class level annotation #SpringBootTest and follow Junit5 rules.
Solution 2 - Or you can use junit-vintage dependency in your project to run both junit4 and junit5 test cases together.
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.3</version>
<scope>test</scope>
</dependency>
Another reason this may be happening is to have declared another surefire plugin in your pom. In my case I migrated an app to spring boot and left this in the pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<includes>
<include>**/*Test*.java</include>
</includes>
</configuration>
<executions>
<execution>
<phase>clean</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Spring boot test were executed after remove this part from the pom.
If none of the above works for you and you are using junit 5 with appropriate annotations, issue might be with Maven Surefire and Failsafe plugins.
This is because of some conflict between the JUnit Surefire provider and the JUnit support in the Surefire 2.22.0 plugin release.
Update your POM to require the 2.22.0 releases of the Maven Surefire and Failsafe plugins.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
Refer here for an example
Adding org.junit.jupiter.api.Test worked for me
With Spring boot 2.5.0
junit-vintage-engine jar isn't added, hence any org.junit.Test won't be run.
Only org.junit.jupiter.api.Test seems to run.
After Adding this jar (junit-vintage-engine) all my old tests(org.junit.Test) run absolutely fine.
This issue can happen because your test class is not public.
this works for my problem to update springboot 2.3.9 to 2.4.3
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.3</version>
<scope>test</scope>
</dependency>
If you are facing this issue with spring boot 3, I had to upgrade my surefire plugin version to 3.0.0-M8
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
</plugin>
For other people who still have the issue. Personally I resolved that by removing :
<packaging>pom</packaging>
from the pom.xml file.
I'm hoping someone can enlighten me on how junit, maven-surefire-plugin or maven controls how many times to run a test, or if there's something in config or property files somewhere that I failed to find/lookup/set that controls the number of times.
For some reason, when I run my tests in maven, they get executed twice. I see it in the console output. I think the maven-surefire-plugin might be part of the reason but I'm not sure.
I run the command:
mvn -Dtest=TestClassBlah test
I see the log msgs in the console that it starts up, runs the tests, gives a summary, then runs it again for whatever reason:
(Log file sanitized and abridged. Pls excuse any typos from the sanitizing)
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestClassBlah 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
<snip snip>
<snip snip>
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.blah.blah.TestClassBlah
<bunch of INFO and other msgs>
<bunch of INFO and other msgs>
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.465 sec
Results :
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-surefire-plugin:2.11:test (tests) # TestClassBlah ---
[INFO] Surefire report directory: /dir/somewhere/for/me
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.blah.blah.TestClassBlah
<bunch of INFO and other msgs again>
<bunch of INFO and other msgs again>
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.767 sec
Results :
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.799 s
[INFO] Finished at: 2014-08-07T18:54:27+01:00
[INFO] Final Memory: 19M/183M
[INFO] ------------------------------------------------------------------------
I can attach my pom.xml file if needed, although, it just lists our plugins, dependencies, repos, etc. It doesn't seem to list number of times to run tests or suppress output from surefire-plugin.
We use the maven-surefire-plugin to post our results in Jenkins. This is my first time using these technologies so I don't know all the tricks of the trade yet. Thanks in advance for any help you can give me.
UPDATE: Here's the pom. Sorry it's kinda long.
<modelVersion>4.0.0</modelVersion>
<groupId>GenericGroupName</groupId>
<artifactId>TestClassBlah</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TestClassBlah</name>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.genericname</groupId>
<artifactId>analytics</artifactId>
<version>1.5-RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.11</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<executions>
<execution>
<id>tests</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bitExpert-nexus-releases</id>
<name>bitExpert nexus</name>
<url>http://10.196.32.21:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
You have an extra execution of maven-surefire-plugin specified in your pom. Maven has a default execution of Surefire that's running as well. If there's a tag under the of Surefire in your pom, you can move that up under the tag for maven-surefire-plugin and it will be applied to the default execution of maven-surefire-plugin. Then you can delete the extra execution.
If you want Surefire to run one way on desktops and another way in Jenkins, that's a good use case for profiles.
Edit: after looking at your pom this should definitely work and only run surefire once:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
You might be able to remove the entire <configuration> tag depending on how test classes are named--Maven normally interprets every class under src/test/java whose name starts with Test or ends with Test or TestCase as a test class. If all your test classes already follow that convention, then configuring Maven to hoover up every class as a test class is just redundant.
The simplest answer to this is that the surefire plugin is specified in your pom (and/or its parents) with more than one execution, or there are two plugins that perform the same action (I haven't seen it with surefire, but sometimes another organization publishes the same artifact under a different name, developers get confused when doing a search and both end up in the project). If you have parent POMs, executions are merged by their id, if the ids differ, there will be multiple executions.
You snipped the important part of the log, which is the line "--- maven-surefire-plugin:2.11:test (tests) # TestClassBlah ---", which includes the plugin artifact ID (maven-surefire-plugin) and execution id (tests). If these lines differ between the two executions, you have your answer.