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

Interceptors


When moving beyond the scope of standalone unit tests and into tests that require resources, it is often the case that we would need to set up these resources before a test and tear them down again later. For example, a database connection may need to be initialized for use by a test and then closed properly once the test is finished. We can do this manually in a test, but if we have a suite of tests, then this soon becomes laborious.

Wouldn't it be nicer if we could just define a function once and and then have it run before and after each test or each suite of tests. This functionality exists in KotlinTest under the name of interceptors. Each type of interceptor is defined to run before and after the code is tested. Let's discuss the different types of interceptors.

The test case interceptor

The first type of interceptor is the test case interceptor. These are interceptors added directly to test cases themselves, and they only apply to the test cases they were added to. A test...