I have some code that runs a test like so:
assertFailsWith<APLEvalException> {
// some code that should throw APLEvalException
}
This test fails, because the code throws ArrayIndexOutOfBoundsException
instead:
Expected an exception of class array.APLEvalException to be thrown, but was java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 4
java.lang.AssertionError: Expected an exception of class array.APLEvalException to be thrown, but was java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 4
at org.junit.Assert.fail(Assert.java:88)
at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
at kotlin.test.AssertionsKt__AssertionsImplKt.checkResultIsFailure(AssertionsImpl.kt:28)
at kotlin.test.AssertionsKt.checkResultIsFailure(Unknown Source)
at array.ArrayLookupBracketsTest.lookupIllegalIndex(ArrayLookupBracketsTest.kt:66)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... a lot of irrelevant strack frames removed ...
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:834)
What I really want to see at this point is the stack trace of the ArrayIndexOutOfBoundsException
that was thrown instead of the expected exception.
Would it make sense to make the original exception be contained as the cause of the AssertionError
so that it would be displayed in the report?