Maven - 单元测试的独立集成测试 [英] Maven - separate integration tests from unit tests

查看:196
本文介绍了Maven - 单元测试的独立集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将集成测试与同一模块中的单元测试隔离开来?

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

我创建了简单的pom:

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>

但是使用 mvn -Pintegration测试时,它不会调用任何内容。如果我在主构建中注释掉排除部分 - 那么它就会开始执行测试,但也没有配置文件。

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.

推荐答案

而不是:

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

尝试:

 <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.

这篇关于Maven - 单元测试的独立集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆