2013-07-17 51 views
3

我的Maven的:Maven無法爲具有多個接口的類中的JUnit類別加載組?

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.15</version> 
       <configuration> 
        <groups> 
         com.rubberduck.TestState.Ready 
        </groups> 
       </configuration> 
      </plugin> 

我的班級:

package com.rubberduck; 
public class TestState 
{ 
    public interface Ready { 
     /* to allow filter ready tests as groups */ 
    }  
    public interface InProgress { 
     /* to allow filter ready tests as groups */ 
    }  
    public interface NotTested { 
     /* to allow filter ready tests as groups */ 
    }  
} 

我的測試:

@Test(timeout = 60000) 
@Category(TestState.Ready.class) 
public void test() throws Exception { 
    assertEquals(true, true); 
} 

我的錯誤:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-cli) on project rubberduck: Execution default-cli of goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test failed: There was an error in the forked process 
java.lang.RuntimeException: Unable to load category: com.rubberduck.TestState.Ready 

如果我給他<groups>com.rubberduck.TestState</groups>它組合物1 les沒有錯誤,但我想有多個接口在同一類中的組,是不是可能?

+0

看到http://stackoverflow.com/questions/19981320/where-should-i-put-interface-class-for-junit-category – gilad

回答

3

你可以像這樣指定類中的接口:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.15</version> 
    <configuration> 
     <groups> 
      com.rubberduck.TestState$Ready 
     </groups> 
    </configuration> 
</plugin> 
0

嘗試使接口定義是靜態的,但這引出了問題,爲什麼不直接在自己的文件中定義每個接口?這絕不會改變您使用它們的能力,或者將它們的多個分配給JUnit測試。

+1

靜態沒有區別,仍然聲稱「無法加載」。我有多個組,我想將它們全部保存在一個文件中。我不是三行java類的忠實粉絲:D – MushyPeas

相關問題