Search code examples
intellij-ideajunitassert

View difference of assertEquals in IntelliJ IDEA for long strings


IntelliJ IDEA has a nice feature to view the differences in JUnit tests when assertEquals check fails. It's explained on their website https://www.jetbrains.com/help/idea/viewing-and-exploring-test-results.html and it usually looks like this:

Click to see difference link

However, sometimes the link to see differences is simply missing and it's not possible to compare anymore. I believe it might be caused by the length of the compared strings, as it works when you compare strings of 3k bytes but does not work with strings of 6k bytes.

Is there a confinguration parameter for this or any workaround to make it work with longer strings?


Solution

  • Please see the answer to your question at the issue: https://youtrack.jetbrains.com/issue/IDEA-142886 You may change the threshold by passing -Didea.junit.message.length.threshold the maximum message length you expect. The threshold was introduced due to performance problems in java.util.regex.Pattern used to detect diff which slows down the tests when output is big.