kotest-assertions-core / io.kotest.matchers.equality / shouldNotBeEqualToIgnoringFields

shouldNotBeEqualToIgnoringFields

fun <T : Any> T.shouldNotBeEqualToIgnoringFields(other: T, vararg properties: KProperty<*>): Unit

Asserts that this is not equal to other without using specific fields

Verifies that this instance is not equal to other without using some specific fields. This is useful for matching on objects that contain unknown values, such as a database Entity that contains an ID (you don't know this ID, and it doesn't matter for you, for example)

Opposite of shouldBeEqualToIgnoringFields

Example:

data class Foo(val id: Int, val description: String)

val firstFoo = Foo(1, "Bar!")
val secondFoo = Foo(2, "BAT!")

firstFoo.shouldNotBeEqualToIgnoringFields(secondFoo, Foo::id) // Assertion passes