Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AssertionFailedError: null on boolean method

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());
}
like image 760
AnthonyW Avatar asked Jun 14 '13 16:06

AnthonyW


1 Answers

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

like image 168
AnthonyW Avatar answered Sep 24 '22 01:09

AnthonyW