Unable to mock Service class in Spring MVC Controller tests

后端 未结 7 800
渐次进展
渐次进展 2020-12-02 06:44

I have a Spring 3.2 MVC application and am using the Spring MVC test framework to test GET and POST requests on the actions of my controllers. I am using Mockito to mock the

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 07:01

    You're creating a mock for PolicyService, but you're not injecting it into your MockMvc as far as I can tell. This means that the PolicyService defined in your Spring configuration will be called instead of your mock.

    Either inject the mock of the PolicyService into your MockMvc by setting it, or take a look at Springockito for injecting mocks.

提交回复
热议问题