Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven Surefire不会触发集成测试_Maven_Testing_Integration Testing_Spring Test_Maven Surefire Plugin - Fatal编程技术网

Maven Surefire不会触发集成测试

Maven Surefire不会触发集成测试,maven,testing,integration-testing,spring-test,maven-surefire-plugin,Maven,Testing,Integration Testing,Spring Test,Maven Surefire Plugin,在我的Spring MVC项目中,我面临着这个问题: 我有两种测试。单元和集成。两者在test/java中由包分隔,分别由test/java/unit和test/java/integration分隔。我正在使用maven surefire插件来触发测试 我在pom.xml中定义了两个配置文件,unit和integration <profile> <id>unit</id> <properties>

在我的Spring MVC项目中,我面临着这个问题:

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

我在pom.xml中定义了两个配置文件,
unit
integration

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

单位
**/单位/***.java
整合
**/集成/***.java
... 为简单起见,省略了用于配置集成平台(DB…)的其他属性
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>

org.apache.maven.plugins
maven surefire插件
2.22.2
${include.tests}
当我运行
mvn surefire:test-Punit
时,所有的单元测试都会被触发,这正是我想要的(我已经检查了通过的测试数量是否与我通过单元文件夹(例如IDEA)触发它们时通过的测试数量相同)

但是当我尝试运行
mvn surefire:test-Pintegration
时,任务将运行并“成功”,但生成的测试数为0。但是当我从IDEA运行这些测试时,例如在
Integration
profile处于活动状态时,我看到有X个测试将成功运行

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


单元测试使用Mockito基于JUnit5。

第一次集成测试应该由maven failsafe插件处理,并遵循命名约定,如
*IT.java
更好。此外,单元测试应该遵循命名约定,就像
*Test.java
一样,并且应该在测试单元的相同包中。除此之外,如果您使用的是JUnit Jupiter(又名JUnit 5),那么使用
@RunWith
是没有意义的,因为它与JUnit 4.X相关,或者您使用的是JUnit Jupiter vintage引擎(或者必须配置,我在这里看不到)。在没有配置文件的情况下,应通过
mvn verify
运行它@khmarbaise我知道目前制定的惯例并不是我能管理的最好的,但这是我现在不能轻易改变的情况。RunWith仅用于集成测试(由于spring测试版本较低,我无法更改它,否则我会更改它)。JUnit5单元测试与此“分离”,并且可以分离。还有其他“旧”测试我不能删除,但我不想运行它们。这就是原因。因此,最基本的是能够以某种方式在/unit和/integration中分别运行测试。基本上自动化我在IDEA(按文件夹运行测试)@khmarbaise Ad2:运行mvn verify不会触发单个测试。构建结束成功,但运行的测试数为0(以便使用集成配置文件运行surefire),首先使用哪个Spring启动版本?@khmarbaise遗憾的是,它不是Spring启动应用程序。但是它的SpringMVC版本是4.3.6(core)(现在没有机会迁移到Boot,邮件的目标是让它工作起来)