Overview
It happens very often that WebTestClient
is used in heavyweight integration tests. It's no use to waste time to check if another condition has been fixed or not. Soft assertions could help a lot to check all conditions at once even if one of them fails.
Proposal
New API would look like as follows:
client.get().uri("/test")
.exchange()
.expectAllSoftly(
exchange -> exchange.expectStatus().isOk(),
exchange -> exchange.expectBody(String.class)
.isEqualTo("It works!")
);
Related Issues
-
26917
Comment From: sbrannen
This PR is blocked until #26917 has been merged into main
.
Comment From: sbrannen
This has been merged into main
in 25dca404138e85e8864e4bfa4b37c88f236a559e and revised in 3c2dfebf4ec5e9d791c1f3c9fa0ad35a5a9fcd6b.
Thanks for the 2nd soft assertions PR! 👍
Comment From: rstoyanchev
Sorry for the late review. Overall looks good, but I've spotted a follow-up issue to be fixed.
Currently individual expectations like responseSpec.expectStatus()
are internally surrounded with ExchangeResult#assertWithDiagnostics
which logs request and response details. That means when multiple assertions are executed, those details are also logged multiple times.
I'm not immediately sure how to solve this, but we'll need to find something.
Comment From: sbrannen
Currently individual expectations like
responseSpec.expectStatus()
are internally surrounded withExchangeResult#assertWithDiagnostics
which logs request and response details. That means when multiple assertions are executed, those details are also logged multiple times.
Good catch.
I'm not immediately sure how to solve this, but we'll need to find something.
OK. Let's brainstorm.
Maybe we could use a ThreadLocal
to track whether that information has already been logged for the current thread.