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 -----
但項目構建路徑有它:
編輯
這是測試類的類路徑
這是在測試類(它是一個庫項目)
我實際上使用Eclipse中的嚮導創建了JUnit測試普通香草。我沒有修補Build Path。爲什麼單元測試者對我的行爲與其他人不同?除此之外,我沒有最微不足道的想法如何檢查你所說的:-( – ilomambo
你確實給了我一個想法,我的測試庫混合測試一些是Junit測試(JUnit4)和一些是Android JUnit測試(JUnit3),所以這可能是問題的根源 – ilomambo
我想我已經弄明白了,因爲我說我有混合測試,但JUnit4庫應該向後兼容JUnit3。但即便如此,如果您的測試擴展了'TestCase',您就無法利用JUnit4引入的新方法(如'assertArrayEquals')必須堅持JUnit3的限制 – ilomambo