测试接收MultipartFile的方法

MultipartFile可以使用Mockito的MockMultipartFile来模拟


@Test
public void compareSuccess() throws Exception {
    // ControllerTest是这个测试类的类名
    URL resource=ControllerTest.class.getResource("/test.xlsx");
    File file = new File(resource.getPath());
    FileInputStream fileInputStream = new FileInputStream(file);
    MockMultipartFile mockMultipartFile = new MockMultipartFile(file.getName(),fileInputStream);
}

Mockito的POM依赖


     org.mockito
     mockito-core
     2.5.5
     test

 

你可能感兴趣的:(编程)