Tag Archives: JUnit

java.lang.RuntimeException: Stub!

I recently tried to run my junit tests to ensure that I didn’t break anything after monkeying around with my code, and I ran into the following error:

Exception in thread "main" java.lang.RuntimeException: Stub!

Here’s my code that runs my tests:

public class RunTestSuite {
public static void main(String[] a) {
TestRunner.run(suite());
}

public static Test suite() {

TestSuite suite = new TestSuite();
suite.addTestSuite(MyClassTests.class);
return suite;
}

}

The stack trace pointed to line 8, so I didn’t know what to make of it since I just had this setup correctly, and TestSuite is a JUnit thing.

Googling mostly resulted in issues with using an Android Test Project (I’m not) and running the tests in your desktop’s JVM instead of the actual device’s (see here).

Eventually, though, I found this post that informed me that the JUnit library needs to be at the top of the test project’s build order.

Here are the steps to change the build order in Eclipse:

  1. Right-click your test project
  2. Click Bulid Path->Configure Build Path…
  3. Click the Order and Export tab
  4. Select the JUnit reference
  5. Click the Top button

If you’d like to see what I’ve been up to with my Android programming, check out my Email Yourself app.

EasyMock Exception NoClassDefFoundError

While trying to set up my JUnit test project in eclipse to be able to mock the dependencies of my classes under test, I was receiving a java.lang.NoClassDefFoundError exception on the call to EasyMock.replay(myMockedObject). Included in my build path were easymock-3.0.jar, objenesis-1.2.jar, and cglib-2.2.jar.

I eventually found this site, and saw that I needed cglib-nodep-2.2.jar in my build path instead of just cglib-2.2.jar. Odd that EasyMock didn’t mention that .jar specifically.