can anyone advise if something fundamental changed...
# announcements
j
can anyone advise if something fundamental changed with how
equals()
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:
Copy code
internal class MyException(cause: Throwable) : RuntimeException(cause)
I then have some code which simply catches any errors and logs:
Copy code
} 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:
Copy code
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:
s
Sorry its not a direct answer, but best way to check would be to debug and inspect actual and expected exception.