【问题标题】:Exclude some test Classes when building spring boot app构建 Spring Boot 应用程序时排除一些测试类
【发布时间】:2017-10-10 13:59:46
【问题描述】:

我有一个大型 java 项目,想为项目的几个部分构建测试类。

我的 Spring Boot 测试文件夹的 Root 包中有 Context 测试。

-Test
 -Root
  -ParentContextTest.class
  -ChildContextTest.class
 -FocusedTest
  -UserPermissioningTest.class <- extends ChildContextTest.class

我想像上面那样安排我的测试包,所以在构建项目时只测试主上下文,并且 FocusedTest 包中的任何内容都不会运行。

FocusedTest 测试类在手动运行测试时扩展了相应的 Context。

我正在使用 spring boot + maven。

任何帮助都会很棒。

我在 pom 中使用 Spring boot Build 如下所示

<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
           <fork>true</fork>
           <executable>true</executable>
           <excludes>
             <exclude>
              <groupId>com.Test.FocusedTest</groupId>
             </exclude>
            </excludes>
      </configuration>
 </plugin>

【问题讨论】:

    标签: java spring testing


    【解决方案1】:

    您可以使用相应的 Maven 插件配置从测试中排除类:

    http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

    【讨论】:

    • 这不适用于 spring boot maven build 插件
    【解决方案2】:

    就我而言,我使用了maven-surefire-plugin(正如@simon-martinelli 提到的那样)并将后缀IntegrationTest 添加到我需要排除的测试中。最后,我使用的配置是:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>**/*IntegrationTest.java</exclude>
            </excludes>
        </configuration>
    </plugin>
    

    mvn test 跳过测试

    使用mvn -Dtest=*IntegrationTest test 运行集成测试

    【讨论】:

      猜你喜欢
      • 2019-11-17
      • 1970-01-01
      • 2015-08-20
      • 2017-04-14
      • 2023-02-16
      • 2018-03-20
      • 1970-01-01
      • 2019-07-16
      • 2017-01-30
      相关资源
      最近更新 更多