我想在springbootjunit测试用例中评估来自rest控制器的布尔响应。响应似乎是相同的,但请放心,在响应值中加了括号。
我的controller:-
@PutMapping("/file/{id}")
ResponseEntity<Boolean> uploadFile(@RequestBody MultipartFile file,
@PathVariable String id) {
return new ResponseEntity<>(
fileService.uploadImage(file, id),
HttpStatus.CREATED);
}
我的测试case:-
@Test
public void UploadAttachmentTest() throws Exception {
given().pathParam("id", "randomId").multiPart(dummyFile).expect()
.statusCode(HttpStatus.SC_CREATED).body(equalTo(true)).when()
.put("/file/{id}");
}
运行junit测试时出错case:-
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: <true>
Actual: true
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:74)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:237)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:249)
....
1条答案
按热度按时间7eumitmz1#
按照您想要的格式提取响应。