【发布时间】:2019-01-15 13:30:42
【问题描述】:
我正在尝试使用我的 API 创建一个用于上传 mp3 文件的测试。我不知道该怎么做。
我的文件 testsound.mp3 位于我项目的资源文件夹中。
我的 API 代码:
@PostMapping(value = "/tracks", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Track create(@RequestParam("file") MultipartFile file) throws IOException, InvalidDataException, UnsupportedTagException {
return trackService.createTrack(file);
}
到目前为止我的测试代码:
@Test
public void eTestUploadTrack() throws IOException {
File file = new ClassPathResource("testsound.mp3").getFile();
trackId = given()
.header("X-Authorization", token)
.param("file", file)
.post("/tracks")
.then()
.statusCode(200)
.extract()
.path("id").toString();
}
我的项目结构:
希望任何人都可以帮助我!
提前致谢!
【问题讨论】:
标签: spring api file testing rest-assured