The issue is caused by org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics
which catches AssertionError, adds diagnostic information and throws a new AssertionError.
The trouble is, that if you use an assertion library in WebTestClient.consumeWith
the assertion library throws an exception with details like org.opentest4j.AssertionFailedError
. The details are used by IDEs when displaying difference between expected and actual value. By rethrowing generic AssertionError, the extra details are lost and the IDE has to use heuristics to guess the difference (for example like this this).
To make it worse, if the IDE guesses wrong, it adds the debugging information from assertWithDiagnostics
to the expected value in the difference view which is really confusing.
The best way would be to rethrow the AssertionFailedError with related detail but I understand that it would add complexity and may require reflection to not break the method when opentest4j is not on the classpath
Comment From: rstoyanchev
Re-recreating the underlying exception would be a challenge indeed. Instead I can experiment with simply logging the diagnostics, e.g. at ERROR, and then re-throwing the original exception as is.
Comment From: lukas-krecan
That makes sense.
Comment From: lukas-krecan
Alternatively, it should be possible to create a method similar to consumeWith
which would pass the diagnostics information to the "consumer".