I use Eclipse and I added JUnit4 in libraries. A have test where I expect exceptions and I use @Test annotations with parameters like this:
@Test(expected = NullPointerException.class)
public void setNullClassLoader() {
Noob.setClassLoader(null);
}
But this is not working. I don't get complete test, I get "test failed" with exception NullPointerException. This is example of my test result:
java.lang.IllegalArgumentException: illegal return count
at com.naef.jnlua.LuaState.lua_pcall(Native Method)
at com.naef.jnlua.LuaState.call(LuaState.java:591)
at com.example.testlualib.tests.LuaStateErrorTest.testIllegalCall2(LuaStateErrorTest.java:256)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1873)
All my tests extends from AndroidTestCase, also I add @RunWith(JUnit4.class) annotation for my main test class:
@RunWith(JUnit4.class)
public abstract class AbstractLuaTest extends AndroidTestCase {
...
}
If you want to run a JUnit 4 test (with the nice annotations) then you must not extend AndroidTestCase. Please remove the
@RunWith(JUnit4.class), too. This runner is deprecated. You should use the default runner which does not need an@RunWithannotation.