mavenmaven-3

Maven - single way to know if tests are skipped


With Maven, there is more than one way to skip running unit and/or integration tests.

For example:

If I'm trying to activate a profile based on the fact that tests are being skipped, how could I reliably do that?

I can activate a profile based on absence of one property, but not two:

    <profile>
        <id>do-something-because-tests-are-skipped</id>
        <activation>
            <property>
                <name>!skipTests</name>
            </property>
            <property>
                <name>!maven.test.skip</name> <!-- Two properties doesn't work -->
            </property>
        </activation>
        <build>
        .....
        </build>
    </profile>

Is there some other way to achieve the desired behaviour?


Solution

  • This has now been implemented in Maven 4.0.0-rc-1

    <profile>
        <id>do-something-because-tests-are-skipped</id>
        <activation>
            <condition>
                <![CDATA[
                    not(${skipTests}) && not(${skipITs}) && not(${maven.test.skip})
                ]]>
            </condition>
        </activation>
        <build>
        .....
        </build>
    </profile>