Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply default ResultHandlers before default ResultMatchers in MockMvc #27225

Closed
1 task done
sbrannen opened this issue Jul 29, 2021 · 0 comments
Closed
1 task done

Apply default ResultHandlers before default ResultMatchers in MockMvc #27225

sbrannen opened this issue Jul 29, 2021 · 0 comments
Assignees
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Jul 29, 2021

Overview

MockMvc.applyDefaultResultActions(MvcResult) currently applies default ResultMatchers before default ResultHandlers. Consequently, if a ResultMatcher fails, no ResultHandler will be applied.

For example, in the following test, if alwaysExpect(content().string("Boom!")) results in an exception, alwaysDo(print(System.err)) will never be applied, and the user will never see the expected debug output to help diagnose the problem.

@Test
void test() throws Exception {
	standaloneSetup(new SimpleController())
		.alwaysDo(print(System.err))
		.alwaysExpect(content().string("Boom!"))
		.build()
		.perform(get("/"));
}

Deliverables

  • Ensure that default ResultHandlers are applied before default ResultMatchers.
@sbrannen sbrannen added in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug labels Jul 29, 2021
@sbrannen sbrannen self-assigned this Jul 29, 2021
@sbrannen sbrannen added this to the 5.3.10 milestone Jul 29, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, MockMvc applied global ResultMatchers before
global ResultHandlers. This lead to unexpected scenarios where a
failing matcher would prevent a handler from being applied.

One concrete use case is `alwaysDo(print(System.err))` which should
print out MockMvc results for debugging purposes. However, if MockMvc is
configured with something like `alwaysExpect(content().string("?"))`
and the expectation fails, the user will never see the expected debug
output to help diagnose the problem.

This commit addresses this issue by applying global ResultHandlers
before ResultMatchers in MockMvc.

Closes spring-projectsgh-27225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant