I'm trying to write some JUnit tests for an Android application.
I've read online that to have a unit test pass if it throws an exception, you would use the @Test annotation like this
@Test(expected = NullPointerException.class)
public void testNullValue() throws Throwable
{
Object o = null;
o.toString();
}
but Eclipse is telling me that this annotation doesn't exist. How can I fix this? If I run the test, it runs fine and fails as expected but obviously I want it to fail (and thus actually pass) :)
You can always bypass it manually:
public void testNullValue()
{
try {
Object o = null;
o.toString();
fail("Expected NullPointerException to be thrown");
} catch (NullPointerException e) {
assertTrue(true);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With