问题
i exclude all tests in plugin except my test suite:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<!--
<configuration>
<groups>ru.csbi.registry.IntegrationTestsNotRequiringContainerCategory</groups>
<groups>ru.csbi.registry.UnitTestsCategory</groups>
</configuration>
-->
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
but all tests are executed.
Even if i delete my the only include in config it still runs all tests:
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<!--
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
-->
</configuration>
Here is the logs:
------------------------------------------------------- T E S T S ------------------------------------------------------- Concurrency config is
parallel='both'
,perCoreThreadCount=true
,threadCount=10
, useUnlimitedThreads=falseRunning javalangtests.AnnotationTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.JdbcServiceTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.ClassServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.FieldServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.hibernate.relation.RelationServiceTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
Effective pom:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</execution>
</executions>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</plugin>
回答1:
You need to remove configuration block from configuration block.
Like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
Nested configuration element makes no sense. As well as package name in your include (ru.csbi.registry.CategorizedTestsSuite.java).
来源:https://stackoverflow.com/questions/9461519/maven-surefire-test-plugin-runs-tests-even-if-they-are-excluded