spring-projects / spring-projects/spring-boot

@WebMvcTest should also auto-configure Spring Data web integration

Open
#9,028 11 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: blocked type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Spring Data's @EnableSpringDataWebSupport registers a couple of Spring MVC extensions that allow the easy consumption of Pageable and Sort instances as well as automatic identifier-to-entity conversion.

When running a test case with @WebMvcTest the auto-configuration that enables this is not activated, which I think is due to the fact that it sort of belongs to Spring Data. However, it fundamentally causes controller methods to behave differently.

I think it should be just fine to include SpringDataWebAutoConfiguration in the set of auto-configurations applied for @WebMvcTest as it doesn't strictly require any downstream Spring Data components but would make sure that mock repository beans would be picked up (so that the id-to-entity-conversion works during bean binding) and the Pageable and Sort resolution works.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how @WebMvcTest selects its auto-configurations and compare that set with SpringDataWebAutoConfiguration. Verify the change with a controller test covering Pageable and Sort resolution and identifier-to-entity conversion; done means these Spring Data web integrations work under @WebMvcTest.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.