Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

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 specific property or condition. In the rest of this section, we will cover some of the most fundamental matchers.

String matchers

One of the most common set of matchers is undoubtedly the String matchers. This is not surprising, given how fundamental...