Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withData ignores assertSoftly configuration #3884

Open
Fleshgrinder opened this issue Feb 19, 2024 · 0 comments
Open

withData ignores assertSoftly configuration #3884

Fleshgrinder opened this issue Feb 19, 2024 · 0 comments
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones.

Comments

@Fleshgrinder
Copy link

I'm using the latest version of Kotest. It doesn't matter where I configure that I want to use soft assertions by default. I'm doing it in the test case in the minimal reproducer, but the same effect applies if it's configured globally via a config class or the properties.

package com.fleshgrinder.kotest

import io.kotest.core.spec.style.StringSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe

class WithDataSoftly : StringSpec({
    assertSoftly = true

    withData(Pair("a", "b"), Pair("c", "d")) {
        it.first shouldBe "x"
        it.second shouldBe "y"
    }
})
Expected :"x"
Actual   :"a"
<Click to see difference>

[…]

Expected :"x"
Actual   :"c"
<Click to see difference>

Wrapping the assertions myself in assertSoftly fixes the issue.

package com.fleshgrinder.kotest

import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.StringSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe

class WithDataSoftly : StringSpec({
    withData(Pair("a", "b"), Pair("c", "d")) {
        assertSoftly {
            it.first shouldBe "x"
            it.second shouldBe "y"
        }
    }
})
io.kotest.assertions.MultiAssertionError: The following 2 assertions failed:
1) expected:<"x"> but was:<"a">
   at com.fleshgrinder.kotest.WithDataSoftly$1$1.invokeSuspend(WithDataSoftly.kt:11)
2) expected:<"y"> but was:<"b">
   at com.fleshgrinder.kotest.WithDataSoftly$1$1.invokeSuspend(WithDataSoftly.kt:12)

[…]

io.kotest.assertions.MultiAssertionError: The following 2 assertions failed:
1) expected:<"x"> but was:<"c">
   at com.fleshgrinder.kotest.WithDataSoftly$1$1.invokeSuspend(WithDataSoftly.kt:11)
2) expected:<"y"> but was:<"d">
   at com.fleshgrinder.kotest.WithDataSoftly$1$1.invokeSuspend(WithDataSoftly.kt:12)

It does however break the <Click to see difference> but that's a different story. 😉

@LeoColman LeoColman added enhancement ✨ Suggestions for adding new features or improving existing ones. assertions 🔍 Related to the assertion mechanisms within the testing framework. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework. labels Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. data-driven-testing 🗃️ Related to the data driven testing mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones.
Projects
None yet
Development

No branches or pull requests

2 participants