5

I get the following error when running this code: (ColorMatrix getarray() returns a float[])

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

the error:

 ----- 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 ----- 

But the project build path has it:

enter image description here

EDIT
This is the Test class classpath enter image description here

This is the class under test (It is a library project) enter image description here

1 Answer 1

4

The stack trace contains the hint for the solution: It contains junit.framework.TestCase (so this class is on the classpath) but later, it can't find org.junit.Assert.

This looks as if you have JUnit 3.8 on the classpath when running the test but JUnit 4 when you compile them.

Find out how the unit test runner builds the classpath and fix it there.

Sign up to request clarification or add additional context in comments.

22 Comments

I actually created the JUnit test plain vanilla using the Wizard in Eclipse. I did not tinker with the Build Path. Why should the unit test runner behave different for me than for anyone else? Apart from that I have not the faintest Idea how to check what you said :-(
You did give me an idea, my test library has mixed tests some are Junit tests (JUnit4) and some are Android JUnit tests (JUnit3) so this might be the source of the problem.
I think I figured it out, as I said I have mixed tests, but JUnit4 library should be backwards compatible to JUnit3. But even so, if your test extends TestCase you cannot take advantage of the new methods introduced by JUnit4 (like assertArrayEquals) you have to stick to JUnit3 limitations.
If both JARs are on the classpath, then odd things can happen if the wrong one is first. You can use JUnit 4 code in JUnit 3 tests by using Assert.assertArrayEquals() If that doesn't work because it picks JUnit 3's Assert, create a helper class which wraps the methods that you want to use.
I tried to do one better and recreate the failure, but I did not succeed. The posted pics are indeed of the working case. I think before that the added libraries (like Xerces and JUnit4) were at the bottom, and the Android dependencies and private libraries were at the top.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.