Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • So I need to mock the JpaRepo in every test classes ? Even if It is not used in the Controller. It's seems weird. With the previous spring version, we needed to mock only the component that were injected in the class that is tested. Commented Mar 14, 2018 at 7:59
  • By default MockMvc is loaded with all context. If you just want to have context for a single controller, create standalone context using MockMvcBuilders.standaloneSetup.... Commented Mar 14, 2018 at 8:01
  • 1
    "We needed to mock only the component that were injected in the class that is tested" - True when you are running test with MockitoJunitRunner. Commented Mar 14, 2018 at 8:04
  • Thanks, I understand my mistake. The new annotation @WebMvcTest does not replace the need to configure the MockMvcBuilders.standaloneSetup(controllerA).build(); Commented Mar 14, 2018 at 8:32