spring boot项目测试类的使用
1 package com.hut.maoyanmovie;
2
3 import com.hut.maoyanmovie.bean.Orders;
4 import com.hut.maoyanmovie.dao.OrdersMapper;
5 import org.junit.jupiter.api.Test;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.test.context.ActiveProfiles;
9
10 @SpringBootTest
11 @ActiveProfiles("dev")
12
13 class MaoyanmovieApplicationTests {
14 @Autowired(required = false)
15 OrdersMapper ordersMapper;
16
17 @Test
18 void contextLoads() {
19
20 ordersMapper.insertOrdersByOid(new Orders(9,5,5,"2020年12月09日"));
21 }
22
23 }
一般是@Autowired注入,然后直接在void contextLoads()方法中直接调用要测试的方法即可
比如上述直接测试
insertOrdersByOid()方法