Search code examples
unit-testingkotlinframeworksassertjkotest

kotest equivalent to usingElementComparatorIgnoringFields from assertJ


assertJ allows you to check for element-wise list equality while ignoring user specified fields like so

assertThat(listOfObjects)
    .usingElementComparatorIgnoringFields("field1", "field2", ...)
    .containsExactly(object1, object2, ...)

I have not been able to find any equivalent function in kotest. Is there an equivalent?


Solution

  • There is no such assertion at collection level, though you can perform similar assertion at individual object using shouldBeEqualToIgnoringFields matcher.

    https://github.com/kotest/kotest/blob/1f4069d78faead65a0d7e8c7f1b689b417a655d2/kotest-assertions/kotest-assertions-core/src/jvmMain/kotlin/io/kotest/matchers/equality/reflection.kt#L127

    https://kotest.io/docs/assertions/core-matchers.html