How does Eclipse actually run Junit tests?

To answer your problem first, if you have a discrepancy between the Ant junit and Eclipse JUnit, it’s probably a classpath or environmental problem. The easiest way is to find a test that performs differently between the two and print out the System properties, and work at it from that direction. Another thing to try … Read more

Failed to load ApplicationContext caused by ArrayIndexOutOfBoundsException in ClassReader

Most likely you have lambda expression inside one of your spring beans. Apparently, spring 3 beans can’t initialize if there is a lambda somewhere in their code. In case migration to spring 4 is not an option, try to rewrite your lambda expressions using anonymous classes, like Function<A,B> lambda = new Function() { public B … Read more

NoSuchFieldError when trying to run a jUnit test with Spring

Are you using an older version of Eclipse (Galileo or before)? or an older version of the junit plugin? If so, this may be the cause of the problem. ParentRunner is looking for Sorter.NULL, which was introduced in JUnit 4.5: package org.junit.runner.manipulation; public class Sorter implements Comparator<Description> { /** * NULL is a <code>Sorter</code> that … Read more

Testing console based applications/programs – Java

Why not write your application to take a Reader as input? That way, you can easily replace an InputStreamReader(System.in) with a FileReader(testFile) public class Processor { void processInput(Reader r){ … } } And then two instances: Processor live = new Processor(new InputStreamReader(System.in)); Processor test = new Processor(new FileReader(“C:/tmp/tests.txt”); Getting used to coding to an interface … Read more

Running ant build gives “package org.junit does not exist”

You should add your junit.jar into the classpath definition in your ant file. There are many way to do it, one example is: <junit printsummary=”yes” haltonfailure=”yes”> <classpath> <path refid=”your.classpath.refid” /> <fileset dir=”${junit.dir}”> <include name=”**/junit.jar” /> </fileset> </classpath> … </junit> See Ant Manual for details on setting up your classpath.

FragmentActivity can not be tested via ActivityInstrumentationTestCase2

I spent half the night on this, and finally found a solution. The key line is: 04-05 18:00:11.276, (Lcom/example/android/app/FragmentLayoutSupport; had used a different Landroid/support/v4/app/FragmentActivity; during pre-verification). The problem is that the android-support-v4.jar which you are using in your test project is different from that one in your application project. Remove all of the references to … Read more