簡體   English   中英

構建 spring boot 應用程序時排除一些測試類

[英]Exclude some test Classes when building spring boot app

我有一個很大的 java 項目,想為項目的幾個部分構建測試類。

我的 Spring Boot 測試文件夾的 Root 包中有 Context 測試。

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

我想像上面一樣安排我的測試包,這樣在構建項目時只測試主上下文,並且 FocusedTest 包中的任何內容都不會運行。

FocusedTest 測試類在手動運行測試時擴展相應的上下文。

我正在使用 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>

您可以使用相應的 Maven 插件配置從測試中排除類:

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

就我而言,我使用了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運行集成測試

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM