TestTimeSource

class TestTimeSource : AbstractLongTimeSource

A time source that has programmatically updatable readings. It is useful as a predictable source of time in tests.

The current reading value can be advanced by the specified duration amount with the operator plusAssign:

val timeSource = TestTimeSource()
timeSource += 10.seconds

Implementation note: the current reading value is stored as a Long number of nanoseconds, thus it's capable to represent a time range of approximately ±292 years. Should the reading value overflow as the result of plusAssign operation, an IllegalStateException is thrown.

Since Kotlin

1.3

Constructors

TestTimeSource
Link copied to clipboard
fun TestTimeSource()

Functions

markNow
Link copied to clipboard
open override fun markNow(): TimeMark

Marks a point in time on this time source.

plusAssign
Link copied to clipboard
operator fun plusAssign(duration: Duration)

Advances the current reading value of this time source by the specified duration.