【发布时间】:2015-08-31 06:10:36
【问题描述】:
我正在使用 groovy 中的 spock 编写集成测试用例。我们正在使用 restTemplate 来调用操作,例如这样
when:
String url="http://localhost:$port/user/password"
ResponseEntity<ResponseWrapper<User>> entity=restTemplate.postForEntity(url,changePasswordDTO,ResponseWrapper.class)
then:
entity.statusCode == HttpStatus.OK
entity!=null
我已经为 POST 和 GET 编写了集成测试,但是现在当我为 PUT 编写它时,我在 entity object 上遇到空指针异常
我已经为 PUT 写了这个,我知道 put 操作将是空的,但是我没有任何其他方法,有人可以帮助我
String url="http://localhost:$port/applicant/{id}/status?blacklistingFlag&reason"
map.put("id", "23")
map.put("blacklistingFlag","0")
map.put("reason","no reason")
restTemplate.exchange(url, HttpMethod.PUT, null, null, map)
ResponseEntity<ResponseWrapper<User>> entity=restTemplate.put(url,ResponseWrapper.class , map)
then:
entity.statusCode == HttpStatus.OK
entity!=null
【问题讨论】:
标签: groovy integration-testing spock