Skip to content

Custom arb will assign null even if field is supposed to use non-null arb #4723

@schielek

Description

@schielek

Which version of Kotest are you using
Tested with kotest 5.9.1, kotlin 2.1.0

Test case

import io.kotest.core.spec.style.FreeSpec
import io.kotest.property.Arb
import io.kotest.property.arbitrary.bind
import io.kotest.property.forAll

data class Foo(val bar: Bar?)

data class Bar(val baz: String)

class PropertyTestCustomARb : FreeSpec({
    val arbBarNotNull = Arb.bind<Bar>()

    val arbFooWithBar: Arb<Foo> = Arb.bind<Foo> {
        bind(Foo::bar to arbBarNotNull) // field should never be null since its Arb does not generate nulls
    }

    "bar should never be null" {
        forAll(arbBarNotNull) { bar ->
            bar != null
        }
    }

    "foo with bar should have bar" {
        forAll(arbFooWithBar) { foo ->
            foo.bar != null // fails
        }
    }
})

Metadata

Metadata

Assignees

Labels

bug 🐛Issues that report a problem or error in the code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions