Hassan Syed February 2016

Include testing test groups for failsafe (integration testing) only but exclude them from surefire

The following config does not work. No test is in scope for the goal integration-test.

In case it is unclear, What should happen is that what I do a mvn integration-test the failsafe plugin should run my test. But the surefire plugin configuration is excluding the test. If I uncomment the surefire config block the test is run during the integration-test goal.

Maven config:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <groups>spring-container-sanity</groups>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludedGroups>spring-container-sanity</excludedGroups>
            </configuration>
        </plugin>
    </plugins>
</build>

A Java Test class

@SpringApplicationConfiguration(TestApplication.class)
@TestPropertySource("/test.properties")
public class SimpleTest extends AbstractTestNGSpringContextTests {
    @Test(groups = "spring-container-sanity")
    public void isHessianServiceExported() throws Exception {
      /*...*/

    }
}

Answers


Hassan Syed February 2016

I don't know why the tests are run when surefire is disabled. Failsafe has a file naming convention for integration tests, if the tests you want to run do not follow this they won't be in scope and the group rule will have nothing to match. So, in this case to get failsafe to resolve the tests it should run correctly you first need to add an include filter. This build block will work:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                <groups>spring-container-sanity</groups>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludedGroups>spring-container-sanity</excludedGroups>
            </configuration>
        </plugin>
    </plugins>
</build>

Post Status

Asked in February 2016
Viewed 2,519 times
Voted 11
Answered 1 times

Search




Leave an answer