2013-04-15 55 views
1

我想刪除單元測試的依賴關係。我發現如何去做in this answer排除對某個特定單元測試的maven依賴關係

但我想刪除只有一個具體測試,而不是我所有的測試依賴項。有沒有辦法做到這一點?

+1

我不這麼認爲,導致依賴是行家模塊。如果您僅需要進行單個測試,則可能需要將此測試移至單獨的Maven模塊。但這聽起來像集成測試,並不像單元測試。也許你可以詳細闡述一點或發佈你的pom文件? – khmarbaise

+0

確實,它更像是一個集成測試,它是在缺少特定依賴時測試我的應用程序的行爲。 – FBB

+1

比你應該把這個測試分解成一個單獨的maven模塊。 – khmarbaise

回答

2

不是通過使用一次Surefire執行。

您將不得不定義兩個Surefire插件的執行:一個包含大部分測試的完整Classpath,另一個包含需要它的單個測試的專用Classpath。

按照一定能成功的插件的文檔:http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

你必須創建兩個處決,並把它們結合到test階段。使用下面的示例作爲骨架(你必須調整includeexclude模式,以及被排除的類路徑神器):

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <executions> 
      <execution> 
       <id>full-cp</id> 
       <phase>test</phase> 
       <goals> 
        <goal>test</goal> 
       </goals> 
       <configuration> 
        <includes> 
         <include>**/Test*.java</include> 
        </includes> 
        <excludes> 
         <exclude>MyFancyTest.java</exclude> 
        </excludes> 
       </configuration> 
      </execution> 
      <execution> 
       <id>special-cp</id> 
       <phase>test</phase> 
       <goals> 
        <goal>test</goal> 
       </goals> 
       <configuration> 
        <includes> 
         <include>MyFancyTest.java</include> 
        </includes> 
        <classpathDependencyExcludes> 
         <classpathDependencyExcludes>excluded-artifact</classpathDependencyExcludes> 
        </classpathDependencyExcludes> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 
+1

Thx。你能不能展示一個配置示例? – FBB

+1

Surefire插件不適用於集成測試。集成測試應該由maven-failsafe插件運行。 – khmarbaise

+0

編輯我的答案 - 希望可以幫助... – Isaac

相關問題