I am testing a method that takes two objects as parameters and returns a boolean
. When I use and assertTrue
or assertFalse
on the method in question I get the following test failure: junit.framework.AssertionFailedError: null
.
I know that I am passing invalid parameters and will likely be causing a NPE within the method but that is not what is happening, instead the test is failing.
Note: I am using boolean
and not Boolean.
Sample Code:
Class:
public class MyClass{
public boolean foo(MyObject1 lhs, MyObject2 rhs){
//doSomething
//return something
}
}
Test:
.... //initilization of myClass, etc.
@Test
public void testFoo(){
assertTrue(myClass.foo(new MyObject1(), new MyObject2());
}
"null
" shows up as the message in a JUnit 3 assert (junit.framework.Assert
) with a blank message parameter. This has been fixed in JUnit 4 (org.junit.Assert
).
Example:
JUnit 3:
assertTrue(false)
has the same stack trace as assertTrue("null", false)
JUnit 4:
assertTrue(false)
has the same stack trace as assertTrue("", false)
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