使用MockMultipartFile测试最大上传文件大小 [英] Test maximum upload file size with MockMultipartFile
本文介绍了使用MockMultipartFile测试最大上传文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Spring Boot创建文件上传服务,并使用Spring Mock Mvc和MockMultipartFile对其进行测试.我想测试超过最大文件大小时是否引发错误.以下测试失败,因为它收到200.
I create a file upload service with Spring Boot and test it with Spring Mock Mvc and MockMultipartFile. I want to test if an error is thrown when the maximum file size is exceeded. The following test fails because it receive a 200.
RandomAccessFile f = new RandomAccessFile("t", "rw");
f.setLength(1024 * 1024 * 10);
InputStream is = Channels.newInputStream(f.getChannel());
MockMultipartFile firstFile = new MockMultipartFile("data", "file1.txt", "text/plain", is);
mvc.perform(fileUpload("/files")
.file(firstFile))
.andExpect(status().isInternalServerError());
是否可以测试上传文件的大小?
Is there any possibility to test the upload file size?
推荐答案
查看全文