Multiplatform testing

In JUnit I have the option to pass an expected exception to the Test annotation. How would I do this in the multi platform environment?

The only test annotation is defined like this

@Target(AnnotationTarget.FUNCTION)
public expect annotation class Test()

I could not find anything related to multi-platform about this.

You can use assertFailsWith function to assert that a code block throws an exception:

@Test 
fun myTest() {
    assertFailsWith<IndexOutOfBoundsException> { list[-1] }
}
2 Likes