Unit testing MockMVC用于带有路径变量和对象的控制器方法

Unit testing MockMVC用于带有路径变量和对象的控制器方法,unit-testing,junit,Unit Testing,Junit,我的控制器如下所示: @RestController @RequestMapping("/v1/controller") public class FindValue { @RequestMapping(path="{id}/Method", method = POST) public ResponseEntity<HttpStatus> setMethodValue (@PathVariable Integer id, @RequestBody FindRequest f

我的控制器如下所示:

@RestController
@RequestMapping("/v1/controller")
public class FindValue {

@RequestMapping(path="{id}/Method", method = POST)
    public ResponseEntity<HttpStatus> setMethodValue (@PathVariable Integer id, @RequestBody FindRequest findRequest) {
但这将返回404错误


有人能帮忙吗?

您有控制器/v1/controller的根reuqest映射,以及资源“{id}/Method的映射

它测试您是否创建了未映射的url: “/v1/controller/{id}/Method

我想应该是这样

@RequestMapping(path="/{id}/Method", method = POST)

而@JB Nizet+1

我本以为会出现NullPointerException,因为mockMvc从未初始化过。那是你真正的密码吗?
@RequestMapping(path="/{id}/Method", method = POST)