doc / ch.tutteli.atrium.api.infix.en_GB / because

because

infix fun <T> Expect<T>.because(keyWithCreator: KeyWithCreator<String, T>): Expect<T> (source)

Allows to state a reason for one or multiple assertions for the current subject.

expect(12) because of("this is true as anything can ever be") {
    toBe(12)
}

fails {
    expect(12) because of("won't hold, it's not equal") {
        toBe(11)
    }
}

expect(listOf(1)) because of("toBe is based on equality, use isSameAs for identity") {
    toBe(listOf(1))
}

fails {
    expect(arrayOf(1)) because of("array has not implemented equals, so is equivalent to isSameAs") {
        toBe(arrayOf(1))
    }
}

Parameters

keyWithCreator - Combines the reason with the assertionCreator-lambda. Use the function of(reason) { ... } to create a KeyWithCreator.

Return
an Expect for the subject of this expectation.

Since
0.15.0