3

我们有一个 REST 服务,我们想对其进行测试。我考虑过为此目的使用 HttpUnit。我们向资源 URL 发送 POST 请求,并在收到请求后从请求中检索文件。在我们的服务器代码中,我们有这样的东西:

MultipartFormData body = request().body().asMultipartFormData();
FilePart file = body.getFile("upfile");
File pictureFile = file.getFile();

在我的测试中,我写道:

WebConversation wc = new WebConversation();
WebRequest wr = new PostMethodWebRequest("http://linkToOurResource");
File f = new File("testFile.jpg");
wr.selectFile("upfile", f, "multipart/form-data;");
    WebResponse response = wc.getResponse(wr);

但我收到以下错误:

Test functional.AcceptanceTests.testAddingNewClient failed: Parameter 'upfile' is not a file parameter and may not be set to a file value.

任何建议如何将 POST 请求中的文件发送到我们的服务器?

4

1 回答 1

0

您可能想阅读 httpunit 开发人员常见问题解答 - 只需搜索 httpunit 的单元测试即可找到合适的源代码示例:

https://sourceforge.net/mailarchive/forum.php?thread_name=5051BBF6.70700%40bitplan.com&forum_name=httpunit-develop

于 2012-10-15T23:11:38.810 回答