Skip to content

Assertion error details lost in rethrow in assertWithDiagnostics #26303

@lukas-krecan

Description

@lukas-krecan

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

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions