-
Notifications
You must be signed in to change notification settings - Fork 686
Closed
Labels
assertions 🔍Related to the assertion mechanisms within the testing framework.Related to the assertion mechanisms within the testing framework.bug 🐛Issues that report a problem or error in the code.Issues that report a problem or error in the code.good-first-issue 👶Suitable for newcomers looking to contribute to the project.Suitable for newcomers looking to contribute to the project.
Description
Kotest version: 5.9.1
Hi, Kotest reports wrong location of a failed assertion inside assertSoftly
when another more complex check is used (e.g., shouldBeEqualToIgnoringFields
).
See this example:
package example
import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
class ExampleFunSpecTest : FunSpec({
data class Data(val x: Int, val y: Int)
// OK
test("assert test") {
val data = Data(1, 2)
data.x shouldBe 3
data.y shouldBe 4
}
// OK
test("assert test / ignoring fields") {
val data = Data(1, 2)
data shouldNotBe null
data.shouldBeEqualToIgnoringFields(Data(3, 4), Data::x)
}
// OK
test("assert softly test") {
assertSoftly(Data(1, 2)) {
x shouldBe 3
y shouldBe 4
}
}
// Wrong location of failed assertion
test("assert softly test / ignoring fields") {
assertSoftly(Data(1, 2)) {
it.shouldNotBeNull()
it.shouldBeEqualToIgnoringFields(Data(3, 4), Data::x)
}
}
})
Reported failure for the last test:
The following assertion for Data(x=1, y=2) failed:
Data(x=1, y=2) should be equal to Data(x=3, y=4) ignoring fields [x]; Failed for [y: 2 != 4]
java.lang.AssertionError: The following assertion for Data(x=1, y=2) failed:
Data(x=1, y=2) should be equal to Data(x=3, y=4) ignoring fields [x]; Failed for [y: 2 != 4]
at example.ExampleFunSpecTest$1$4.invokeSuspend(ExampleTest.kt:83)
at example.ExampleFunSpecTest$1$4.invoke(ExampleTest.kt)
...
The test file has 44 lines - there is no line 83.
When clicking the (ExampleTest.kt:83)
in IntelliJ idea, selecting Navigate to -> inline function call site
leads me at least to the assertSoftly
block, but not to the concrete failed assertion there.
Metadata
Metadata
Assignees
Labels
assertions 🔍Related to the assertion mechanisms within the testing framework.Related to the assertion mechanisms within the testing framework.bug 🐛Issues that report a problem or error in the code.Issues that report a problem or error in the code.good-first-issue 👶Suitable for newcomers looking to contribute to the project.Suitable for newcomers looking to contribute to the project.