Hi, I have folowing setup for test:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
I am autowiring MockMvc
without problems. I just noticed that TestDispatcherServlet
is set for MockMvc
object and I am worrying that this should actually be forbidden configuration, shouldn't it?
I have discovered that in HttpServletRequest.getRequestUrl
, there are these values:
1: for MockMvc
it targets http://localhost/myservice - so to port 80 which differs from @LocalServerPort
2. for standard application startup from jar it targets the port correctly: http://localhost:
Is this a bug or this is valid configuration to have MockMvc
and RANDOM_PORT
setup?
Thank you.
Comment From: snicoll
MockMvc is about mocking the MVC layer so it doesn't use the network at all.
If you have further questions, please follow-up on StackOverfow, as mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.