robstoll / atrium

A multiplatform expectation library for Kotlin
https://docs.atriumlib.org
European Union Public License 1.2
566 stars 210 forks source link

show only failing sub assertions in a summary assertion group #724

Open robstoll opened 3 years ago

robstoll commented 3 years ago

Platform (all, jvm, js): all Extension (none, kotlin 1.3): none

Code related feature

Consider the following reporting

expected that subject: {a=null, null=1, b=2}        (java.util.LinkedHashMap <1031246792>)
◆ contains only, in order: 
  ✔ ▶ element 0: a=null        (java.util.LinkedHashMap.Entry <1834736756>)
      ◾ ▶ key: "a"        <528658809>
          ◾ equals: "a"        <528658809>
      ◾ ▶ value: null
          ◾ equals: null
  ✘ ▶ element 1: null=1        (java.util.LinkedHashMap.Entry <601057428>)
      ◾ ▶ key: null
          ◾ equals: null
      ◾ ▶ value: 1        (kotlin.Int <1614645392>)
          ◾ is less than: 1        (kotlin.Int <1614645392>)

Atrium could be more helpful in spotting the error for element: 1 by only showing the failing assertions:

  ✘ ▶ element 1: null=1        (java.util.LinkedHashMap.Entry <601057428>)
      ◾ ▶ value: 1        (kotlin.Int <1614645392>)
          ◾ is less than: 1        (kotlin.Int <1614645392>)

Also, I think it would be enough if the successful assertions only show that an element was successful but not the assertions behind it. So after all improvements it would look like the following:

expected that subject: {a=null, null=1, b=2}        (java.util.LinkedHashMap <1031246792>)
◆ contains only, in order: 
  ✔ ▶ element 0: a=null        (java.util.LinkedHashMap.Entry <1834736756>)
  ✘ ▶ element 1: null=1        (java.util.LinkedHashMap.Entry <601057428>)
      ◾ ▶ value: 1        (kotlin.Int <1614645392>)
          ◾ is less than: 1        (kotlin.Int <1614645392>)

In the spirit of #292, it would make sense that one can configure the assertion function to show all assertions or not within the summary assertion group. But per default, sub assertions within an summary assertion group should only be shown if failing.

jakubriegel commented 1 year ago

Hi! I'll do it

robstoll commented 1 year ago

@jakubriegel thanks but this isn't an easy one and I will tackle it myself in the context of another change. Please focus on another issue if you want to support Atrium