2013-07-25 56 views
-1

出於某種原因,我的測試類工作並通過eclipse,但如果我嘗試從命令行使用mvn test -Dtest=BmwTest它失敗。它給的理由是:junit理論不適用於maven

java.lang.AssertionError: Never found parameters that satisfied method assumptions. Violated assumptions: [] 

我的代碼:

@RunWith(Theories.class) 
public class BmwTest { 

    @DataPoints 
    public static Integer[] a = { 
      1, 
      2, 
      3 
    }; 

    @Theory 
    public void testMyTest(Integer a) { 

    } 

} 

我一直使用原語(int)嘗試,它仍然給出了同樣的錯誤。單數註釋@DataPoint起作用,但複數註釋@DataPoints不起作用。這是怎麼回事?非常感謝!謝謝

+2

我試過你的代碼,它通過Eclipse和Maven可以正常工作。我使用Maven 3和JUnit 4.9。您使用的是Maven和JUnit版本? – user2507946

回答

0

我做了一些挖掘,結果證明junit-dep導致了這個問題。我檢查了測試類路徑,並且包含了junit.jar和junit-dep.jar。基本上,它們是相同的,唯一的區別是junit-dep.jar不包括hamcrest庫。如果你想知道junit-dep是從哪裏來的,那麼它就是jmock的一個依賴,我忘了提及我們正在使用它。我刪除了我的pom中的junit-dep依賴項,並且一切正常。

<dependency> 
    <groupId>org.jmock</groupId> 
    <artifactId>jmock-junit4</artifactId> 
    <version>2.6.0</version> 
     <exclusions> 
      <exclusion> 
       <groupId>junit</groupId> 
       <artifactId>junit-dep</artifactId> 
      </exclusion> 
     </exclusions> 
</dependency>