Testing Top-Level Functions
The Airport class we designed using tests has the facility to return the information about a single airport and to sort a list of airports by name. We need a function that will take a list of airport codes and return a sorted list of airport information. We’ll implement that function in a new AirportStatus.kt file, as a top-level function rather than as a method of a class. It turns out testing a top-level function isn’t any different than testing a method of a class, as we’ll see soon.
In the spirit of growing code incrementally using tests, let’s first implement a simple, synchronous version of a getAirportStatus() function that takes a list of airport codes and returns a sorted list of Airport instances filled ...
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.