版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37681914/article/details/80614195
使用Junit结合mock做单元测试遇到的问题。原因缺少@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:/testContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
//加上 @WebAppConfiguration
@WebAppConfiguration
public class UserMarketingActivityControllerTest {
@Resource
private UserMarketingActivityController userMarketingActivityController;
@Resource
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
}