Skip to content

I want to test that my business logic times out #417

@swankjesse

Description

@swankjesse

I want to write a test that does something like this:

  @Test
  fun testingBusinessLogicThatDoesTimeouts() = runTest {
    val turbine = Turbine<String>()
    assertFailsWith<TimeoutCancellationException> {
      withTimeout(1.seconds) {
        turbine.awaitItem()
      }
    }
  }

Unfortunately it fails like so:

Expected an exception of class kotlinx.coroutines.TimeoutCancellationException to be thrown, but was app.cash.turbine.TurbineAssertionError: No value produced in 3s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions