Matchers
Matchers test for some property, indicated by the name of the matcher, beyond simple equality. For example, a matcher may check whether a string is empty or whether an integer is positive. In the getting started guide, we used the assertion shouldBe
to check for equality. In fact, the assertion shouldBe
also accepts a matcher that provides for more complicated assertions.
The idea behind the shouldBe
naming convention is to lead to readable assertions, such as thisString shouldBe empty()
. To further this goal, there is an equivalent of shouldBe
, named should
; with this, matchers such as thisString
should startWith("foo")
could be read as natural language.
Many matchers are provided by KotlinTest out of the box, and each one checks for some ...
Get Programming Kotlin now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.