SpringBoot项目单元测试

今天,需要用到单元测试,于是使用了旧事的SpringTest,发现启动不了。

直接Ctrl+ F 搜索Caused by, 找到了原因,因为原来是SSM项目,所以用的是

@ContextConfiguration(locations = { "classpath:applicationContext.xml" })

报错,找不到applicationContext.xml,于是百度了一下,发现这个博客 写的很有道理。

于是改成了

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = Application.class)  //这里的Application是springboot的启动类名

再次启动Test方法,启动虽然比较慢,但是还是成功了.

猜你喜欢

转载自blog.csdn.net/m0_37961948/article/details/81698097