Maven - separate integration tests from unit tests

与世无争的帅哥 提交于 2019-12-18 03:16:16

问题


Is it possible to isolate integration tests from unit tests within same module?

I created simple pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>prj</artifactId>
    <packaging>war</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/integration/**/*.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>integration</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <includes>
                                <include>**/integration/**/*.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

however with mvn -Pintegration test it doesn't invoke anything. If I comment out excludes section in main build - then it starts to execute tests, but without profile as well.


回答1:


instead of:

<exclude>*/integration/**/*.java</exclude>

try:

 <include>*/unit/**.java</include>

then in the integration profile do

<includes>
   <exclude>**/unit/**/*.java</exclude>
   <include>**/integration/**/*.java</include>
</includes>

you may have to play with getting the includes/excludes exactly right, but that's the general idea.



来源:https://stackoverflow.com/questions/8185936/maven-separate-integration-tests-from-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!