I (think that I) want to write a test that asserts...
# kotlinx-datetime
l
I (think that I) want to write a test that asserts that a specific amount of Duration has passed, but unsure how to do it. Or, in different words: given an Instant, I would like to simulate running in the future. Do I need some kind of mutable Clock, or should I use timeMark?
m
My back-end exclusively uses a
Clock
instance provided through dependency injection. During unit testing a custom simulated clock instance is provided.
l
@Marc Knaup do you advance/rewind the time in your tests? I also inject the
Clock
interface in my SUT, but I am unsure how to test it
m
Yeah, roughly like that:
Test code simply calls
clock.advance()
to simulate a different time. Optionally it can state how much time has passed.
Timestamp
would be
Instant
for you I guess :)
l
Fantastic! It looks very similar to what I think I need
m
It’ll make a note to add a
ManualClock
to my
fluid-time
library 🙂
🙌 1
I’ve released fluid-time 0.12 with
ManualClock
for unit testing: https://github.com/fluidsonic/fluid-time#readme