Skip to content

Instantly share code, notes, and snippets.

@happysundar
Created February 3, 2014 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happysundar/8793780 to your computer and use it in GitHub Desktop.
Save happysundar/8793780 to your computer and use it in GitHub Desktop.
maven integration tests

Dividing tests into unit-test and integration-test in mave

We use the "failsafe" plugin in maven to run and manage integration tests.

Usually, when you build your project, you want to skip running the integration/regression tests;

So, you 'exclude' them from the usual 'test' phase by adding this (in the xpath /pom:project/pom:build/pom:plugins/pom:plugin) in your pom.xml:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <excludes>
                        <!-- even if you wanted to run all the unit tests, do not run the regression test (since it depends on a local logfile) -->
                        <exclude>**/*RegressionTest.java</exclude>
                    </excludes>
                    <skipTests>${skipTests}</skipTests>
                </configuration>
            </plugin>

Now, add a the following section :

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <includes>
                        <include>**/*RegressionTest.java</include>
                    </includes>
                </configuration>
            </plugin>

You can now run the regression test by doing:

mvn clean test-compile failsafe:integration-test -DskipTests=false

To see how you can run a single test, read : https://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment