测试Dao接口是否有问题
利用测试类来看dao层是否有问题,分别用三个测试方法测试三个dao接口。
测试类如下:
package com.cao.frs;
import com.cao.frs.dao.InvoiceMapper;
import com.cao.frs.dao.ReimburseMapper;
import com.cao.frs.dao.UserMapper;
import com.cao.frs.entities.Invoice;
import com.cao.frs.entities.Reimburse;
import com.cao.frs.entities.Users;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@SpringBootTest
class FrsApplicationTests {
@Autowired
UserMapper userMapper;
@Autowired
InvoiceMapper invoiceMapper;
@Autowired
ReimburseMapper reimburseMapper;
@Test
void contextLoads() {
userMapper.remove(4);
userMapper.add(new User(4,"北京",new Date(),"123@13.com",1,"教授","123","12354566","pro",200));
HashMap<String, Object> map = new HashMap<>();
map.put("id",1);
map.put("city","天津");
map.put("isAdmin",0);
map.put("limit",500);
userMapper.update(map);
List<User> all = userMapper.findAll();
for (User users : all) {
System.out.println(users);
}
}
@Test
void test1(){
invoiceMapper.add(new Invoice(6,"小绿","交通",200,1,new Date(),"122122Ad","xxxx大学"));
List<Invoice> list1 = invoiceMapper.searchByName("小红");
for (Invoice invoice : list1) {
System.out.println(invoice.toString());
}
invoiceMapper.remove(6);