Java 测试 REST 网络服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/203495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Testing REST webservices
提问by anjanb
My organization is working on building RESTful webservices on JBoss appserver. The QA team is used to testing SOAP webservices so far using SoapUI. SoapUI has a new version that has REST capabilities. We're considering using that.
我的组织正致力于在 JBoss 应用服务器上构建 RESTful Web 服务。到目前为止,QA 团队习惯于使用 SoapUI 测试 SOAP Web 服务。SoapUI 有一个具有 REST 功能的新版本。我们正在考虑使用它。
- Are there any publicly available RESTful services available on the net for free that someone could test ?
- What tools are available(and used) for testing RESTful web services ?
- 网上是否有任何公开可用的 RESTful 服务可以免费测试?
- 哪些工具可用于(和使用)测试 RESTful Web 服务?
采纳答案by Ole Lensmar
soapUIwill do the job as well, check out this blog postto get started.
回答by Jonathan Arkell
CURL Gets you halfway there. The other half is checking the headers, response codes and entity content to make sure its good. You could use a variety of tools for that (in shell scripting land, piping the header and contents to files, and diffing them might just do the trick). It wouldn't be that difficult to further refine the toolset, maybe stacking curl up with the unit-testing framework of your choice.
CURL 让你走到一半。另一半是检查标头、响应代码和实体内容以确保其良好。为此,您可以使用各种工具(在 shell 脚本领域,将标题和内容通过管道传输到文件,然后对它们进行差异化可能就行了)。进一步完善工具集并不会那么困难,也许与您选择的单元测试框架堆叠在一起。
I built a rest webservice testing panel with AJAX. It wasn't that difficult at all actually. You have some security issues to work out (i.e. making sure that you have the test suite on the same server, or maybe signed Javascript.)
我用 AJAX 构建了一个 rest webservice 测试面板。其实并没有那么难。您有一些安全问题需要解决(即确保您在同一台服务器上拥有测试套件,或者可能签署了 Javascript。)
回答by S.Lott
You can exercise web services using fairly trivial bits of Python. Depending on your security, you may be able to simply use Python's urllib
or urllib2
to do do you REST requests and examine your answers.
您可以使用相当琐碎的 Python 来练习 Web 服务。根据您的安全性,您可以简单地使用 Pythonurllib
或urllib2
执行 REST 请求并检查您的答案。
Additionally, you might want to use Python unittest
to control the execution of the Python tests of your REST services.
此外,您可能希望使用 Pythonunittest
来控制 REST 服务的 Python 测试的执行。
class TestSomeREST( unittest.TestCase ):
def setUp(self):
REALM = "[email protected]"
self.client= RESTClient( "localhost", 18000, "tester", "tester", REALM )
def test_1_get(self):
response = self.client.get('/this/that/other/2/')
self.failUnlessEqual(200, response.status_code)
j1= JSONDecoder().decode(response.content)
self.assertEquals(2, j1[0]['pk'] )
entity= j1[0]['fields']
self.assertEquals('Some Other Group', entity['name'])
self.assertEquals('E1G2', entity['customer_id'])
The RESTClient class uses urllib2 to pass through digest authentication for each request. It's rather complex, but I can share the essence if it's of interest.
RESTClient 类使用 urllib2 为每个请求传递摘要认证。它相当复杂,但如果感兴趣,我可以分享其本质。
回答by S.Lott
Try Python's httplib. It's very easy, you specify the method, url, and use urllib.urlencode for the parameters/POST body.
试试 Python 的 httplib。这很容易,您指定方法、url,并使用 urllib.urlencode 作为参数/POST 主体。
This can be combined with the builtin unittest module if you like, for reporting of errors.
如果您愿意,可以将其与内置的 unittest 模块结合使用,以报告错误。
回答by user28192
Please try Firefox addon Poster , which is simple to use and gets you up nd running quickly
请尝试使用 Firefox 插件海报,它使用简单,可以让您快速上手
回答by Mike Desjardins
I've been using JMeter for this, especially for stuff like load testing. It's similar to SoapUI (which I've also used), but geared more toward testing web pages, which makes it pretty decent at testing RESTful services, too.
我一直在为此使用 JMeter,尤其是对于负载测试之类的东西。它类似于 SoapUI(我也使用过),但更适合测试网页,这使得它在测试 RESTful 服务方面也相当不错。
回答by Mike Desjardins
I've written a program specifically for testing REST Web Services. Its a pretty simple application written in .NET 2.0 (I've only tested it on Windows Vista, but should work on XP also). The application uses HttpWebRequest to make requests, and displays the resulting response, as well as the headers for the request and response. I've done a bit of testing, but I thought it might help you test your web services.
我编写了一个专门用于测试 REST Web 服务的程序。它是一个用 .NET 2.0 编写的非常简单的应用程序(我只在 Windows Vista 上测试过,但也可以在 XP 上运行)。应用程序使用 HttpWebRequest 发出请求,并显示结果响应以及请求和响应的标头。我已经做了一些测试,但我认为它可以帮助您测试您的网络服务。
回答by Valentin Jacquemin
I don't have tested it yet but this Java app seems to be nice to test REST services. There is also a tutorial on Javalobby about it.
我还没有测试过,但这个 Java 应用程序似乎很适合测试 REST 服务。还有一个关于 Javalobby 的教程。
Java App: http://code.google.com/p/rest-client/
Java 应用程序:http: //code.google.com/p/rest-client/
Tuto: http://java.dzone.com/announcements/wiztoolsorg-restclient-21-rele
教程:http: //java.dzone.com/announcements/wiztoolsorg-restclient-21-rele
回答by Clangon
SOA Cleaner, is a test tool that tests both soap and rest (also WCF, but it seems you don't need that feature). It's very intuative, and usable. Written in .NET. A free version is also available. can be downloaded from http://xyrow.com. Good luck!
SOA Cleaner 是一个测试工具,可以同时测试soap 和rest(也是WCF,但您似乎不需要该功能)。它非常直观,并且可用。用 .NET 编写。还提供免费版本。可以从http://xyrow.com下载。祝你好运!