gammay
gammay

Reputation: 6215

JUnit: selectively not run a few test cases as default

Is it possible not to run some of the JUnit test cases by default at build time?

Goal:

We have two kinds of test cases:

On build server, we do not want integration tests to be run (DB not available, etc.). However, unit tests should be run. Currently we achieve this by keeping the integration tests commented out in CM and enabled by developers as needbed.

This is a cumbersome arrangement. What we would like to have is as a default, tell maven to run only unit tests. One way this can be done I suppose is to keep integration tests in a separate package which is not part of default build. However, this will keep test target code and test cases physically separate and typically go out of sync over time.

Any good solutions?

Upvotes: 2

Views: 604

Answers (1)

Henrik
Henrik

Reputation: 1807

You could use different profiles in pom. In default you exclude integrationtests.

<plugin>
     <artifactId>maven-surefire-plugin</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
     <version>2.9</version>
     <configuration>
         <skip>false</skip>
         <useFile>false</useFile>
         <argLine>-Xms1024m -Xmx1024m -XX:MaxPermSize=512m</argLine>
         <excludes>
             <exclude>**/*IntegrationTest.java</exclude>
         </excludes>
     </configuration>
</plugin>

<profiles>
    <profile>
        <id>integration-test-builder</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <groupId>org.apache.maven.plugins</groupId>
                    <version>2.9</version>
                    <configuration>
                        <skip>false</skip>
                        <useFile>false</useFile>
                        <argLine>-Xms1024m -Xmx1024m -XX:MaxPermSize=512m</argLine>
                        <excludes>
                            <exclude>none</exclude>
                        </excludes>
                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>integration-tests</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>    
</profiles>

To run integrationstest you simple do: mvn clean integration-test -P integration-test-builder

Upvotes: 2

Related Questions