Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Failsafe Plugin is always skipping integration tests

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?

like image 294
Michael Avatar asked Mar 04 '15 21:03

Michael


Video Answer


2 Answers

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.

like image 187
Michael Avatar answered Oct 14 '22 06:10

Michael


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

like image 22
Alexander Avatar answered Oct 14 '22 06:10

Alexander