java junit 单元测试代码样例

maven中要导的包:

 
  org.springframework
  spring-test
  4.1.0.RELEASE


  junit
  junit
  RELEASE
@RunWith(SpringJUnit4ClassRunner.class)
//告诉junit spring配置文件
@ContextConfiguration("classpath:applicationContext.xml")
/*@WebAppConfiguration注解是为了应对swagger影响单元测试添加的*/
@WebAppConfiguration
public class UserTest {
    @Autowired
    private UserService userService;

    @Test
    public void getUser()  {
        System.out.println("ininin");
        UserInfo userInfo = new UserInfo();
        userInfo = userService.getUserByName("告鸟");
        System.out.println(userInfo.getUsername());
        for(RoleInfo r : userInfo.getRoleInfoList()){
            System.out.println(r.getRolename());
        }

    }
}

你可能感兴趣的:(java junit 单元测试代码样例)