https://kotlinlang.org logo
Title
p

peekandpoke

11/02/2020, 1:55 PM
Hi there! Has anyone observed "weird" behaviour when combining
assertSoftly
with
shouldNotBe
? I just upgraded from the old kotlintest to kotest:4.3.1 and now some of my tests fail. When I remove the surrounding
assertSoftly
block then everythings is fine again. The assertions stay the same but do no longer fail! It also seems to only happen when I use
shouldNotBe
Any idea? Thanks!
l

LeoColman

11/02/2020, 7:20 PM
Could you give us a code example of that?
p

peekandpoke

11/02/2020, 9:38 PM
Hey yes I have an example:
enum class SimpleEnum {
    First,
    Second
}

data class WithSimpleEnum(val enumValue: SimpleEnum = SimpleEnum.First)

class AssertSoftlySpec : StringSpec({

    "asserting me softly" {

        val source = WithSimpleEnum(enumValue = SimpleEnum.First)

        val result = WithSimpleEnum(enumValue = SimpleEnum.Second)

        assertSoftly {
            withClue("simple strings") {
                "a" shouldBe "b"
                "a" shouldNotBe "b"
            }

            withClue("more complex with data class and enums") {
                source shouldBe result
                source shouldNotBe result
            }
        }
    }
})
The will output:
The following 4 assertions failed:
1) simple strings
expected:<"b"> but was:<"a">
	at de.peekandpoke.ultra.AssertSoftlySpec$1$1.invokeSuspend(AssertMeSoftlySpec.kt:26)
2) more complex with data class and enums
expected:<Second> but was:<First>
	at de.peekandpoke.ultra.AssertSoftlySpec$1$1.invokeSuspend(AssertMeSoftlySpec.kt:31)
3) more complex with data class and enums
expected:<WithSimpleEnum(enumValue=Second)> but was:<WithSimpleEnum(enumValue=First)>
	at de.peekandpoke.ultra.AssertSoftlySpec$1$1.invokeSuspend(AssertMeSoftlySpec.kt:31)
4) more complex with data class and enums
expected:<Second> but was:<First>
	at de.peekandpoke.ultra.AssertSoftlySpec$1$1.invokeSuspend(AssertMeSoftlySpec.kt:32)
So the situation is: I was not able to produce the behaviour with scalar types like strings. But as you can see, in this part both assertions fail, while this should be impossible (or my logic-chip is broken)
withClue("more complex with data class and enums") {
    source shouldBe result
    source shouldNotBe result
}
What do you think is going on here?