Mar 12, 2012

Maven Profile -conditionally exclude junits

Our dataaccess layer is dependent on special software components that are not available in every developer’s sandbox. By default we exclude these tests, but we still need our continuous integration environment (Bamboo) to run all the tests.  
We were able to leverage Maven’s Profile to conditionally exclude tests.

We created a maven property in our pom: exclude.tim.tests


We used this property in exclude configuration.

Running, mvn clean install excludes these tests.

To include the tests, we created a profile IncludeSpecialTests and configured the test exclusion property with a dummy value (NothingToExclude)
    <id>IncludeSpecialTests </id>

Running mvn install  runs all the tests.
mvn clean install –PIncludeSpecialTests