Johan Haleby edited this page Jul 24, 2018 · 5 revisions

Awaitility has a support module called awaitility-kotlin that contains a file called AwaitilityKt (in package org.awaitility.kotlin which contains some useful extension functions.

untilCallTo

Import this extension function (import org.awaitility.kotlin.untilCallTo) and then you can write tests like this:

val myRepository : MyRepository = ...

// Wait until call to myRepository.count() is equal to 3
await().untilCallTo { myRepository.count() } matches { count -> count == 3 }

Other Examples

As of version 3.1.2 you can also do for example:

await withPollInterval ONE_HUNDRED_MILLISECONDS ignoreException IllegalArgumentException::class untilAsserted  {
    assertThat(fakeRepository.value).isEqualTo(1)
}

or

await withAlias "Kotlin Test" ignoreExceptionsInstanceOf
      IllegalArgumentException::class withPollDelay ONE_HUNDRED_MILLISECONDS withPollInterval
      fibonacci().with().offset(1).and().timeUnit(MILLISECONDS) atLeast TWO_HUNDRED_MILLISECONDS atMost
      ONE_MINUTE untilCallTo { fakeRepository.value } matches { it == 1 }

Use the following Maven dependency:

<dependency>
    <groupId>org.awaitility</groupId>
    <artifactId>awaitility-kotlin</artifactId>
    <version>${awaitility.version}</version>
</dependency>

Example

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.