首先引入依赖:
在 Test 文件夹, 创建相关包, 然后创建测试类. 增加2个注解:
@RunWith(SpringRunner.class) //底层用 Junit, SpringJunit4ClassRunner
@SpringBootTest(class={XXXapplication.class}) // 就是启动整个springboot 工程的类.
TestCase 是用来写断言的. 直接在这个 testOne 上右键 run as Junit test, 这样, 就会整个 springboot 启动来测试.
也可以选中这个 class , run as Junit test. 测试这个class 里的所有的测试方法.
@AutoConfigureMockMvc 可以模拟 client 请求, 虽然, 我们有 Postman, 但是, postman 是针对单个 controller 的测试,
而使用这个 MockMvc 可以是可以针对批量的 controller 来进行测试的
java -jar xxx.jar --debug (会显示更多启动信息)
原文:https://www.cnblogs.com/moveofgod/p/14634896.html