Surefire 不会触发集成测试

问题描述

我在 Spring MVC 项目中遇到了这个问题:

我有两种类型的测试。单元和集成。两者在 test/java 中由包分隔,分别由 test/java/unit 和 test/java/integration 分隔。我正在使用 maven-surefire 插件来触发测试。

我在 pom.xml 中定义了两个配置文件unitintegration

<profile>
    <id>unit</id>            
    <properties>
        <include.tests>**/unit/**/*.java</include.tests>
    </properties>
</profile>
<profile>
    <id>integration</id>            
    <properties>
        <include.tests>**/integration/**/*.java</include.tests>
        ... other properties for configuring integration platform (DB,...) omitted for simplicity
    </properties>
</profile>

而surefire插件是这样配置的

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <includes>
                    <include>${include.tests}</include>
                </includes>
            </configuration>
        </plugin>

当我运行 mvn surefire:test -Punit 时,所有单元测试都被触发,这就是我想要的(我检查过的测试数量与我通过单元文件夹触发它们时通过的测试数量相同,例如从想法)。

但是当我尝试运行 mvn surefire:test -Pintegration 时,任务将运行并“成功”,但执行的测试次数为 0。但是当我从 IDEA 运行这些测试时,例如使用 Integration 配置文件活动,我看到有 X 个测试将成功运行。

基本集成测试使用 @RunWith(SpringJUnit4ClassRunner.class) 运行测试(加上一些配置 xml 来配置其他属性)。

单元测试基于 JUnit 5,使用 Mockito。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)