Unit testing: Fixing the system clock with MockK

Niel de Wet
1 min readFeb 14, 2019

--

Photo by Nick Fewings on Unsplash

Unit tests involving time often leads to brittle tests because assertions on time relies on the tests executing fast enough, or slightly better, extra boilerplate test code to check that the timestamp on that object is close enough to the expected value to be correct. With MockK’s static mocks it is easy to set the system clock to a fixed instant.

--

--