junit-team / junit4

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

assertEquals will hang on large object inputs #1670

Closed beForged closed 4 years ago

beForged commented 4 years ago

Ran across this issue when doing property based testing mostly, but if the toString() of the objects compared are too large and they fail, assertEquals will attempt to return the strings as a message and will hang. I haven't found anywhere where this is documented, and was quite difficult to actually diagnose since I assumed that the test was failing due to code timing out, not JUnit timing out, so suggest either doing some sort of default response if the message string is too large, having a cutoff for length where the message is truncated, or somehow making it a little clearer why the test is hanging.

marcphilipp commented 4 years ago

Could you please get a thread dump of the hanging JVM?

beForged commented 4 years ago

I did a thread dump and found out that it probably was a naive toString() implementation on my side that ended up causing this hang to occur. I would argue that the reliance on toString() should probably be mentioned somewhere, since this was quite a difficult bug to track down (and I misinterpreted it at first)

marcphilipp commented 4 years ago

Well, what else would assertEquals() call to create a String representation of the arguments in case of failure? I don't think documenting that it calls toString() would be helpful. Thus, I'm closing this issue. If you feel strongly that this needs to be addressed, please feel free to comment or raise a new, more focussed, issue.