AssertionFailedError: null on boolean method

拈花ヽ惹草 提交于 2019-12-08 20:41:17

问题


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());
}

回答1:


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



来源:https://stackoverflow.com/questions/17112757/assertionfailederror-null-on-boolean-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!