Writing Empirical Tests
We'll cover the following
Empirical tests
Empirical tests are common in unit testing—you call a method and verify that it did what you expected. Such tests help us to verify that, as code evolves, the expectations are still met and the code continues to work as intended.
Empirical tests are useful for functions and methods that are deterministic and don’t have any dependencies that hold state. We’ll create a few empirical tests for the Airport
class now.
First, let’s create some properties in the test suite using the yet-to-be-written Airport
class. For this, within the AirportTest
class, let’s define a few sample properties before the init()
function:
// AirportTest.kt
val iah = Airport("IAH", "Houston", true)
val iad = Airport("IAD", "Dulles", false)
val ord = Airport("ORD", "Chicago O'Hare", true)
We can write a new test, right after the canary test, to exercise the properties of Airport
, like so:
Get hands-on with 1400+ tech skills courses.