Skip to content

Conversation

lorenzodee
Copy link
Contributor

Set resource base path to make @WebMvcTest behave the same as @WebAppConfiguration and @SpringBootTest

This fixes issue #16484 .

Upon further investigation, when running tests that use @WebAppConfiguration or @SpringBootTest, the resourceBasePath (in WebMergedContextConfiguration) was being set to src/main/webapp for servlet-based environments. But when using @WebMvcTest, the resourceBasePath was being set to "" (empty string). This causes the difference in behavior.

In the sample tests in #16484 , the empty string resourceBasePath causes the resource to be missing, since it was not looking under src/main/webapp.

@pivotal-issuemaster
Copy link

@lorenzodee Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@lorenzodee Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 8, 2019
@philwebb philwebb added for: merge-with-amendments Needs some changes when we merge type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 8, 2019
@philwebb philwebb added this to the 2.1.x milestone Apr 8, 2019
@philwebb
Copy link
Member

philwebb commented Apr 8, 2019

Thanks, I'm tempted to look at extracting a method in SpringBootTestContextBootstrapper so we can share that identical logic. We should ideally also try to add a test for this.

@lorenzodee
Copy link
Contributor Author

Thanks Phil. I'd like to help, if I may. Would it be proper to add a test in WebMvcTestAutoConfigurationIntegrationTests that would check for a resource under src/main/webapp?

@lorenzodee
Copy link
Contributor Author

Ended up adding tests in separate test classes. Similar to what was done in SpringBootMockServletContextTests. Hope this helps.

@wilkinsona wilkinsona removed the for: merge-with-amendments Needs some changes when we merge label Jun 17, 2019
@wilkinsona wilkinsona self-assigned this Jun 17, 2019
@wilkinsona wilkinsona changed the title Set resource base path for @WebMvcTest @WebMvcTest ignores base path configured via @WebAppConfiguration Jun 17, 2019
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.6 Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants