TestTimeSource

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
@ExperimentalTime 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.

Constructors

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

<init>

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

TestTimeSource()

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

plusAssign

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

operator fun plusAssign(duration: Duration)
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

read

This protected method should be overridden to return the current reading of the time source expressed as a Long number in the unit specified by the unit property.

fun read(): Long

Extension Functions

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

measureTime

Executes the given function block and returns the duration of elapsed time interval.

fun TimeSource.measureTime(block: () -> Unit): Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

measureTimedValue

Executes the given block and returns an instance of TimedValue class, containing both the result of function execution and the duration of elapsed time interval.

fun <T> TimeSource.measureTimedValue(
    block: () -> T
): TimedValue<T>

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/-test-time-source/index.html