james
07/07/2021, 4:31 AMequals()
works or how kotlin.test.Assertions
might handle RuntimeExceptions
between Kotlin v1.3.62 and v1.5.20? I have a unit test that is more than a year old which started failing when I updated the version of Kotlin.
details:
I have a custom exception class, MyException:
internal class MyException(cause: Throwable) : RuntimeException(cause)
I then have some code which simply catches any errors and logs:
} catch (e: Exception) {
myLogger.logException(MyException(e))
}
Now inside the unit test, we want to confirm that we’re catching exceptions, transforming them to our type, and logging. So the exception is thrown and then log is checked as such:
val exception = RuntimeException("some failure!")
...
...
loggedExceptions.latest() shouldBeInstanceOf MyException::class
(loggedExceptions.latest() as MyException).cause shouldBeEqualTo exception
that final line now fails with the following:
java.lang.AssertionError: Expected <java.lang.RuntimeException: some failure!>, actual <java.lang.RuntimeException: some failure!>.
to reiterate, nothing about this unit test (or the class which it is testing) has changed in over a year. I can’t explain what could be happening here? would greatly appreciate it if someone could shine any light on this.
see attached the version diff:Sourabh Rawat
07/07/2021, 5:19 AM