Skip to content

Comments

Render rich assertion diff#5295

Draft
mpkorstanje wants to merge 3 commits intomainfrom
render-rich-assertion-diff
Draft

Render rich assertion diff#5295
mpkorstanje wants to merge 3 commits intomainfrom
render-rich-assertion-diff

Conversation

@mpkorstanje
Copy link
Contributor


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@mpkorstanje
Copy link
Contributor Author

mpkorstanje commented Jan 23, 2026

For discussion:

There are several challenges in rendering a rich diff based on the actual and expected values.

  1. The string representation of actual and expected values depend on toString() implementation. For most classes this is a single line. But not consistently so.
    1.a. Exception: AssertJ does format the string representation and use multi-line formatting for collections, but only if the collections/strings are large enough.
    1.b. This could be overcome by using more complex formatting. Or using the opentest report instead for the POC.
  2. While with Support accurate programatic presentation of AssertionFailedError ota4j-team/opentest4j#210 in place we can "substitute" the exception message. We don't have enough information to know if an assertion library either provided a reason, provided a null reason or didn't implement the reason yet.
  3. MultipleFailuresError needs special handling too.
  4. String representations might inherently not be diffable without special treatment for example Set::toString does not render elements in a legible order.
    4.a. Sorting could be an option, but elements might not be comparable.

Suggestions:

  1. Wait adoption.
  2. After adoption limit rich diffs to assertions on String.
  3. Introduce a DiffableRepresentation object to mark string representations as diff-able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant