Hi All, Someone help me how to mock this in KMM an...
# multiplatform
h
Hi All, Someone help me how to mock this in KMM androidTest
Copy code
Clock.System.now()
g
I'd wrap the call in a class (I've a TimeProvider in my current project to handle that, with a method
now()
) so that I can mock the class and pass the value I want without thinking about the Kotlin stdlib mock-ability.
👍 2
h
You could simple implement the
Clock
interface and increase the internal counter in your test.
Copy code
@ExperimentalTime
class MockClock(private var durationSinceEpoch: Duration = Duration.ZERO) : Clock {
    override fun now(): Instant = Instant.fromEpochMilliseconds(durationSinceEpoch.inWholeMilliseconds)

    operator fun plusAssign(duration: Duration) {
        durationSinceEpoch + duration
    }
}