@Junit Mybatis SpringBoot 单元测试流程梳理
Junit Mybatis SpringBoot Controller Service Dao 单元测试流程梳理
踩坑预警
- 将包名之前的test.去掉 就没有 unable to find a @SpringBootConfiguration 的错误了
idea 整合 Junit
编写数据库连接父测试类
在 xml 里使用对象 url 的时候 注意 多个 连接 的 配置 用 & 分割
用 xml 配置 mybatis 的 resource 记得
<mappers
<mapper>
</mapper>
</mappers>
Controller 的单元测试
- 使用 Mockmvc 模拟网络请求
- 遇到 通过设置 .contentType(MediaType.APPLICATION_JSON)解决了问题
mvc.perform(MockMvcRequestBuilders.post("url")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_JSON_UTF8)