【发布时间】:2019-09-01 06:58:34
【问题描述】:
我已经编写了基本的 Spring Spock 测试并且我能够成功地做到这一点,但关键是现在我在我的帖子请求中调用的 URL 不是相对的,而是指向我的本地的
http://localhost:88/rty/user/user1/applications/ZZZ78R/users/409?username=ABCedit
所以如果这在测试环境中运行,localhost 将不可用,所以请告知我应该如何在下面的 Spock 测试用例中更正我的 URL
@SpringBootTest
class AuthenticationFactorControllerSpec extends Specification {
def "Should get status 201 when server is up and post request is made"() {
when:
HttpEntity<String> httpEntity = new HttpEntity<String>()
ResponseEntity entity = new RestTemplate().postForEntity("http://localhost:88/rty/user/user1/applications/ZZZ78R/users/409?username=ABCedit", httpEntity, String.class)
then:
entity.statusCode == HttpStatus.CREATED
}
}
【问题讨论】: