0

I am trying to manually convert my JUnit tests into AssertJ, but I'm running into some blockers. None of the scripts or plugins I've found online are working for me.

I have a number of JUnit assertThrows tests

runTest {
    assertThrows<Exception> {
        //suspend function
        messagePublisher.publish(//message)
    }
}

That I'm trying to convert to the equivalent assertJ functionality.

I figured it would be something like

runTest {
    assertThatExceptionOfType(Exception::class.java).isThrownBy {
        // the same suspend function
        messagePublisher.publish(message)
    }
}

But I'm running into an error saying

Suspension functions can be called only within coroutine body

What would be the correct conversion of assertThrows in JUnit to AssertJ?

I suppose an alternative question is how to test suspend functions in AssertJ?

bensalerno
  • 467
  • 1
  • 6
  • 22

0 Answers0