mybatis中的单元测试
一、引入依赖
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>test</scope>
</dependency>
二、配置数据库连接
spring:
datasource:
url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MySQL
username: sa
password: sa
driver-class-name: org.h2.Driver
schema: classpath:META-INF/online_food_init.sql
data: classpath:META-INF/admin.sql
三、编写测试类
@ActiveProfiles("h2")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = OnlineFoodOrderApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AdminMapperTest {
@Autowired
private AdminMapper adminMapper;
@Test
public void testSelectAll(){
List<AdminPO> adminPOS = adminMapper.selectAll();
System.out.println(adminPOS);
}
}