2015-10-21 140 views
0

Apache Maven Surefire site具有以下示例語法排除在運行測試:有沒有一種方法使用surefire在測試方法級別排除測試 - 而不是類級別?

<configuration> 
    <excludes> 
    <exclude>**/TestCircle.java</exclude> 
    <exclude>**/TestSquare.java</exclude> 
    </excludes> 
</configuration> 

這排除類,但如果你想排除測試是一類具有一堆其他的測試 - 然後在每個測試班級將被排除在外,不管你是否只想排除一項測試。

這看起來並不是很精細。我想從一個具有多個測試的類中排除一個測試。

我的問題是:有沒有一種方法使用surefire在測試方法級別排除測試 - 而不是類級別?

回答

0

我不認爲有一個選項 - 甚至不是一個隱藏的。 JUnit自己獲取它應該掃描測試執行的文件列表。見JUnitCore

surefire插件允許區分groups中的測試。另請參閱Stackoverflow上的this answer和此Blog

這可能是一個選項?

0

使用JUnit> = 4.8和類別=> http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html

1. Add : public interface SlowTests{} 

2. public class AppTest { 
     @Test 
     @Category(com.mycompany.SlowTests.class) 
     public void testSlow1() { 
     System.out.println("testSlow1"); 
     } 

     @Test 
     @Category(com.mycompany.SlowTests.class) 
     public void testSlow2() { 
     System.out.println("testSlow2"); 
     } 

     @Test 
     public void test3() { 
     System.out.println("test3"); 
     } 

     @Test 
     public void test4() { 
     System.out.println("test4"); 
     } 
    } 

3. 
<plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.11</version> 
     <configuration> 
     <groups>com.mycompany.SlowTests</groups> 
     </configuration> 
    </plugin> 
相關問題