Take the 2-minute tour ×

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:


public class MyClass{
  public boolean foo(MyObject1 lhs, MyObject2 rhs){
    //return something


.... //initilization of myClass, etc.
public void testFoo(){
  assertTrue(myClass.foo(new MyObject1(), new MyObject2());
share|improve this question
The error you see is normal if the method foo return false. That means that it should probably not throw a NPE as your expect. By the way, you are using JUnit 4 (because of the annotation @Test) but you still use the the old JUnit 3 Assert class (of package junit.framework). –  LaurentG Jun 14 '13 at 16:12
I think you did not encounter a nullpointer inside, you can test this by running the method outside of the asserTrue. Let me know the result. –  Vegard Jun 14 '13 at 16:12
The null is the message you didn't give to the assertTrue method. junit.sourceforge.net/javadoc/org/junit/… –  Brian Roach Jun 14 '13 at 16:13
@LaurentG. is there a new Assert class? What is the difference? –  AnthonyW Jun 14 '13 at 16:23
@Vegard I attempted to store the result in a temporary variable and did not recieve my expected NPE, however both assertTrue & assertFalse still fail. –  AnthonyW Jun 14 '13 at 16:24
show 6 more comments

1 Answer

up vote 2 down vote accepted

"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).


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)

share|improve this answer
add comment

Your Answer


