Вопрос

I met a problem when I use maven failsafe plugin to run integration test. I have two classes one is TestUnitTest.java the other is TestIntegrationIT.java. in pom.xml, I configure as below:

<plugin>                
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*IT.java</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>unit-tests</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <includes>
            <include>**/*IT.java</include>
        </includes>
    </configuration>                    
    <executions>
        <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>                           
            </goals>
        </execution>
    </executions>
</plugin>

when I run mvn:integration-test, will execute both tests, when I run mvn failsafe:integration-test then only run the "TestIntegrationIT". Why output the different results?

Это было полезно?

Решение

The includes for maven-surefire-plugin are defined like *Test, *TestCase whereas maven-failsafe-plugin are defined with IT.java, IT.java or *ITCase.java. So you don't need to define includes for maven-surefire-plugin or maven-failsafe-plugin use the defaults. If you wan't to name an integration test just name it NameIT.java whereas a unit test can be named like NameTest.java. To run your unit tests and/or the integration test you should use the lifecylce either:

mvn package

which will run the unit tests whereas

mvn verify

will run the unit tests and the integration tests.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top