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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (2)

Write a response