junit-team / junit4

A programmer-oriented testing framework for Java.
https://junit.org/junit4
Eclipse Public License 1.0
8.51k stars 3.24k forks source link

Assert error messages are not clear #1752

Closed BMomani closed 1 year ago

BMomani commented 1 year ago

I have this error message

18:16:27  java.lang.AssertionError
18:16:27    at somepackege.SomeTestClass.sometestMethod(SomeTestClass.java:145)

and when going there I see I used assertTrue(whatever) the message should say expected true but that did not happen, or whatever better messages than just AssertionError and similar to other assert methods

bhuvanaindukuri commented 1 year ago

There are 2 options available for assertTrue

public static void assertTrue(String message, boolean condition)

and

public static void assertTrue(boolean condition)

Why not use the first one instead of the second one? Providing a generic error message doesnt add much value here since there are only 2 values possible and if the condition fails it is very obvious that the value is not true and is false. If you prefer to see a proper error message which gives more context of the test, option 1 could be used.

@BMomani - Please let us know in case this option doesnt work for you for some reason.

kcooney commented 1 year ago

This is a duplicate of #1030 which was closed.

@BMomani please review the discussion in that bug (particularly the comment from dsaff on Nov 18, 2014). If you still feel that we should change the behavior, please comment on that bug so all of the discussion is in one place.