AssertionFailedError: null on boolean method
"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)
AnthonyW
Updated on June 04, 2022Comments
-
AnthonyW almost 2 years
I am testing a method that takes two objects as parameters and returns a
boolean
. When I use andassertTrue
orassertFalse
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()); }