2014-03-06 14 views
4

運行此代碼時,我得到以下錯誤:(嘉洛斯getarray()返回float [])的JUnit的NoClassDefFoundError上org.junit.Assert本身

74 public void testHueShift() { 
75  ColorMatrix cm1 = new ColorMatrix(); 
76  ColorMatrix cm2 = hueShift(0f); 
77  assertArrayEquals(cm1.getArray(), cm2.getArray(), 0f); 
78 } 

錯誤:

----- begin exception ----- 
java.lang.NoClassDefFoundError: org.junit.Assert 
    at com.Common.lib.test.ColorFilterFactoryTest.testHueShift(ColorFilterFactoryTest.java:77) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at junit.framework.TestCase.runTest(TestCase.java:154) 
    at junit.framework.TestCase.runBare(TestCase.java:127) 
    at junit.framework.TestResult$1.protect(TestResult.java:106) 
    at junit.framework.TestResult.runProtected(TestResult.java:124) 
    at junit.framework.TestResult.run(TestResult.java:109) 
    at junit.framework.TestCase.run(TestCase.java:118) 
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) 
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) 
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545) 
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551) 
----- end exception ----- 

但項目構建路徑有它:

enter image description here

編輯
這是測試類的類路徑 enter image description here

這是在測試類(它是一個庫項目) enter image description here

回答

3

堆棧跟蹤包含了解決方案的提示:它包含junit.framework.TestCase(所以這個類是在類路徑中)但後來,它找不到org.junit.Assert

這看起來好像有junit 3.8的類路徑上時運行的測試,但JUnit 4中,當你編譯他們。

瞭解單元測試運行器如何構建類路徑並將其修復。

+0

我實際上使用Eclipse中的嚮導創建了JUnit測試普通香草。我沒有修補Build Path。爲什麼單元測試者對我的行爲與其他人不同?除此之外,我沒有最微不足道的想法如何檢查你所說的:-( – ilomambo

+0

你確實給了我一個想法,我的測試庫混合測試一些是Junit測試(JUnit4)和一些是Android JUnit測試(JUnit3),所以這可能是問題的根源 – ilomambo

+0

我想我已經弄明白了,因爲我說我有混合測試,但JUnit4庫應該向後兼容JUnit3。但即便如此,如果您的測試擴展了'TestCase',您就無法利用JUnit4引入的新方法(如'assertArrayEquals')必須堅持JUnit3的限制 – ilomambo

相關問題