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 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.