JUnit4测试代码示例

时间:2021-08-24 02:39:48
 1 @RunWith(SpringJUnit4ClassRunner.class)  2 @SpringBootTest(classes = DuchaApplication.class)  3 public class TestSysRole {  4  @Autowired  5     private RoleService roleService;  6 
 7  @Test  8     public void testFindAll() {  9         ResultMapper<List<SysRole>> findAll = roleService.getAllRole(); 10         for (SysRole sysRole : findAll.getData()) { 11             System.out.println(sysRole.getRoleCode() + "," + sysRole.getRoleName()); 12  } 13 
14  } 15 
16  @Test 17     public void testFindById() { 18         ResultMapper<SysRole> findOne = roleService.findById("735d686c-17fb-4aac-9660-2b928cdbfc6e"); 19         SysRole sysRole = findOne.getData(); 20         System.out.println(sysRole.getRoleCode() + "," + sysRole.getRoleName()); 21 
22  } 23 
24  @Test 25     public void testSave() { 26         SysRole sysRole = new SysRole(); 27         sysRole.setRoleCode("管理员"); 28         sysRole.setRoleName("lzy"); 29         /*
30  * ResultMapper<SysRole> saveOrUpdate = roleService.saveOrUpdate(sysRole); 31  * System.out.println(saveOrUpdate.getData().getId()); 32          */
33  roleService.saveOrUpdate(sysRole); 34  } 35 
36  @Test 37     public void testUpdate() { 38         SysRole sysRole = new SysRole(); 39         sysRole.setId("4942a2ac-c783-46eb-afbd-cd3c6cea76a2"); 40         sysRole.setRoleCode("qaz"); 41         sysRole.setRoleName("xxx"); 42         /*
43  * ResultMapper<SysRole> saveOrUpdate = roleService.saveOrUpdate(sysRole); 44  * System.out.println(saveOrUpdate.getData().getId()); 45          */
46  roleService.saveOrUpdate(sysRole); 47  } 48 
49  @Test 50     public void testDeleteById() { 51         ResultMapper<Boolean> b = roleService.delRole("4942a2ac-c783-46eb-afbd-cd3c6cea76a2"); 52         System.out.println(b.getCode()+","+b.getMsg()+","+b.getData()); 53  } 54     
55  @Test 56     public void testDeleteByRoleName() { 57         ResultMapper<Boolean> b = roleService.deleteByRoleName("lzy"); 58         System.out.println(b.getCode()+","+b.getMsg()+","+b.getData()); 59  } 60     
61     
62 }