我正在使用 Ratpack 的TestHttpClientPOST
在 Spock 测试中为 REST API发送请求。API 的端点接受该参数myPostParam
作为请求正文/POST 参数的一部分。
我看到有一种post
方法可以执行 POST 请求,但我不知道如何发送参数myPostParam=123456
import ratpack.groovy.test.GroovyRatpackMainApplicationUnderTest
import ratpack.test.http.TestHttpClient
import ratpack.test.ServerBackedApplicationUnderTest
import spock.lang.Specification
class MyApiSpecification extends Specification {
ServerBackedApplicationUnderTest aut = new GroovyRatpackMainApplicationUnderTest()
@Delegate
TestHttpClient client = testHttpClient(aut)
def "Doing a API call for Stackoverflow"() {
given:
int myPostParam = 123456
when:
post("/api/v1.0/someMethod/")
// TODO: How do I add "myPostParam=$myPostParam" to the request body?
then:
response.statusCode == 201
response.body.text.empty
}
}