Maven surefire tests - includes and excludes

I have a class A.java and two test classes, ATest.java and AITests.java. The ITest is for integration. The tests must be performed as:

  1. When no Maven profile is selected only the Atest must be tested.

  2. When the itests profile is activated the both tests (ATest and AITest) must be tested.

The problems is, when I use the command

mvn -P itests test

then only the ATest is tested, without the AITest. But I have no idea what I am missing here. Any hint?

My pom.xml is:

...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
                <excludes>
                    <exclude>**/*ITest.java</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>itests</id>
        <activation>
            <property>
                <name>itests</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M4</version>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
...

Upvotes: 0

Views: 241

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35805

For integration tests, please use the Maven failsafe plugin:

https://maven.apache.org/surefire/maven-failsafe-plugin/

You can skip it on the command line if you prefer.

Upvotes: 1

Related Questions