使用mockMvc测试文件上传

阅读更多

@Autowired BanksController banksController; @TestpublicvoidtestAdd() throws IOException { RegisterConfig.RootPath = "E:\\work\\Admin"; FileInputStream fis = new FileInputStream("E:\\Images\\1.gif"); MockMultipartFile file = new MockMultipartFile("file","1.gif","image/jpeg",fis); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest() ; request.addFile(file); request.setParameter("name","test"); request.setParameter("value","tttt"); request.setParameter("isUse","true"); JsonResultObject jsonResultObject = banksController.add(request); System.out.println(jsonResultObject.getData()); }

你可能感兴趣的:(junit)