0

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user1438980
  • 187
  • 1
  • 3
  • 13

1 Answers1

1

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.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I know the reason not as the your mentioned. Since Maven has the default lifecycle, when run mvn integration-test , this phrase will run mvn test firstly. so need to add customized maven lifecycle to make it. – user1438980 Aug 28 '12 at 08:22
  • 1
    You should run mvn verfiy and not mvn integration-test, cause the post-integration phase will not be running. Furhtermore i suggest to name your tests accordingly to the rules and check the documentation of the maven-surefire-plugin cause it has a possibility to skip the test. – khmarbaise Aug 28 '12 at 09:01