如何在单元测试中将模拟的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
}