6
votes

I am attempting to configure my Maven project to have unit tests and integration tests. The unit tests are already working fine using the Maven Surefire plugin and are named according to the pattern *Test.java.

After adding the Failsafe plugin, like so:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <dependencies>
              <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.18.1</version>
              </dependency>
            </dependencies>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

I added an integration test named SomeTestIT.java. However, when I run:

mvn failsafe:integration-test

I get the following:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyApp 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default-cli) @ MyApp ---
[INFO] Tests are skipped.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.368 s
[INFO] Finished at: 2015-03-04T14:43:50-06:00
[INFO] Final Memory: 11M/219M
[INFO] ------------------------------------------------------------------------

My test class (buried a few package levels deep beneath the test hierarchy) looks something like:

package com.example.my.package;

import org.junit.Test;
import org.junit.Assert;
import com.example.my.package.SomeService;

import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.beans.factory.annotation.Autowired;

@RunWith(SpringJUnit4ClassRunner.class)
public class SomeTestIT
{
    @Autowired
    private SomeService target;

    @Test
    public void testTest()
    {
        Assert.assertTrue(false);
    }

    @Test
    public void basicListTest()
    {
        Assert.assertNotNull(target);
    }
}

Where the tests are stubs to make sure that I have the Maven integration working.

I have ensured that:

  • My POM includes a direct, test scoped dependency on JUnit.
  • I have tried the plugin configuration both with and without an explicit test runner dependency.
  • I have tried the configuration above both with and without an explicit include pattern (on the assumption that my class ought to have been picked up by the defaults).

Nonetheless, the tests never actually run. Is there anything else necessary to get the integration tests running?

3
Have you tried mvn integration-test? (you should actually use verify and configure the plugin like maven.apache.org/surefire/maven-failsafe-plugin/usage.html, since integration-test will only run the tests, whereas verify will check the results and break the build when necessary). What's the directory containing the test-sources? - Robert Scholte
All three targets, integration-test, verify and failsafe:integration-test all had the same outcome. The last one one was useful while troubleshooting the issue because it allowed me to only kick off the integration tests. - Michael
Run the command again with an additional -X for logging with debug level and check the plugin configuration. There are probably other hints as well which explain why the tests are skipped. - Robert Scholte

3 Answers

14
votes

I finally figured out what was going on and wanted to keep anyone else from spinning their wheels like I did. In the <properties> tag at the head of the POM, someone had added a property that read <skipITs>true</skipITs>. There were no integration tests previously, so the property was useless. It was probably cargo-culted out of some other POM without any real regard for what it is or what it does.

4
votes

My problem was that maven failsafe plugin was already defined in some parent pom and was configured oddly.

In general, the best way I have found to handle this kind of issues is to first look at the effective pom:

mvn help:effective-pom

and check (1) all properties (2) the configuration of the problematic plugin

2
votes

IntelliJ users should be sure to check their settings!

As shown in the screenshot below, there is an option in

Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner

If checked, Maven will skip integration tests in the failsafe plugin! It seems to have a similar effect as skipITs in one of the other answers. However, because IntelliJ passes it as an argument to its Maven command, it of course does not show up in the effective POM (also mentioned in a different answer).

the skip tests option