Thursday, August 6, 2015

Run a Maven test only when a certain Profile exists

I had a test that would only run on a different OS than my main work, and beyond that it really should only run from a docker container.

This shows how to make it not run by default, but to only run with this maven option set on the command line: -Pnative-test
Here is a sample command line:
mvn -o surefire:test -Pnative-test

To set this up, add this to your pom (the includes can be wildcarded):

<profiles>
    <profile>
        <id>native-test</id>
        <activation>
            <property>
                <name>native-test</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/RunOnlyWithProfile-NativeT.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

edit: updated tag

No comments:

Post a Comment