如何在单元测试中将模拟的 Form 对象传递给 Handler?这是我到目前为止得到的参考:
https://ratpack.io/manual/current/testing.html
https://danhyun.github.io/2016-gr8confus-testing-ratpack-apps/
这是我的处理程序的代码:
void handle(Context context) throws Exception
{
def queryParams = context.request.queryParams
context.parse(Form).then {form ->
String mnemonic = queryParams ['mnemonic']
String series = queryParams ['series']
String volume = queryParams ['volume']
String issue = queryParams ['issue']
UploadedFile cover = form.file("cover")
...
}
这是到目前为止的单元测试片段:
def form = Mock(Form)
form.file(_) >> Mock(UploadedFile)
def result = GroovyRequestFixture.handle(handler) {
RequestFixture fixture ->
fixture.uri("/task/node-asset/update-cover-image?"+
"mnemonic=$mnemonic&series=$mnemonic&volume=$volume&issue=$issue")
//Pass Mock Form
}