springboot使用h2数据库对dao层(mybatis)进行单元测试
此博客用于记录项目对dao层进行操作数据库的单元测试走过的坑,因为考虑到程序员自己进行白盒测试,如果直接操作数据库(虽然也是测试数据库),但会扰乱测试人员辛苦制造的数据,所以直接使用h2内存数据库进行测试。这是我入职的第一份任务,给原有项目写单元测试。
一、h2的配置
- 创建配置文件test/resource/applicationContext.xml
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc=