@RequestMapping(value =“ / getRoles”,method = RequestMethod.GET)公共List <Roles> getRoles(){返回(List <Roles>)roleRepository.findAll(); }

时间:2019-12-02 07:23:48

标签: assert findall test-coverage

 main method:
    @RequestMapping(value="/getAllUsers",method=RequestMethod.GET)
        public List<UserRoleAssoc>  getAllUsers() {
            List<Users> userLst = (List<Users>) userRepository.findAll();
            final List<UserRoleAssoc>  userRoleAssociationList = new ArrayList<UserRoleAssoc>();
                for(Users users : userLst) {
                    List<UserRoleAssoc> userRoleAssoList = userRoleAssociationRepository.getRoleByuserId(users.getUserId());
                    if (userRoleAssoList != null) 
                    {
                        for (UserRoleAssoc userRoleList : userRoleAssoList) {
                            userRoleAssociationList.add(userRoleList);
                        }
                    }

                }
            return userRoleAssociationList;
        }
    test case:
/* start getAllUsers*/
    @Test
public void getAllUserstest() throws Exception {
        MockHttpServletResponse response = mvc.perform(get(restEndPoints.GET_ALL_USERS.uri() + 987)
                .contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse();
        assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
        assertNotNull(response.getContentAsString());} 

我实际上无法编写这些测试用例,使用findall的GET和POst方法很难覆盖

0 个答案:

没有答案