kotest-assertions-core / io.kotest.matchers.date / java.time.LocalDate / shouldBeBefore

shouldBeBefore

infix fun LocalDate.shouldBeBefore(date: LocalDate): Unit

Asserts that this is before date

Verifies that this is before date, comparing year, month and day. For example, 09/02/1998 is before 10/02/1998, and this assertion should pass for this comparison.

Opposite of LocalDate.shouldNotBeBefore

    val firstDate = LocalDate.of(1998, 2, 9)
    val secondDate = LocalDate.of(1998, 2, 10)

    firstDate shouldBeBefore secondDate    // Assertion passes


    val firstDate = LocalDate.of(1998, 2, 10)
    val secondDate = LocalDate.of(1998, 2, 9)

    firstDate shouldBeBefore secondDate     // Assertion fails, 10/02/1998 is not before 09/02/1998 as expected.

See Also

LocalDate.shouldNotBeAfter