java 网络服务单元测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2570896/
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
Web service unit testing
提问by Tony
I'm using JAX-WS web services (client and exposed services), is there any API to test these web services?
我正在使用 JAX-WS Web 服务(客户端和公开服务),是否有任何 API 来测试这些 Web 服务?
采纳答案by Bozho
- test the services out of their "web-service" context.
- Use WSUnitto test consumers.
- take a look at this article
Unit tests are meant to test units of code. They should test business logic, and not infrastructure. So this is not exactly "unit-testing" if you want to test the services within the web-service context.
单元测试旨在测试代码单元。他们应该测试业务逻辑,而不是基础设施。因此,如果您想在 Web 服务上下文中测试服务,这不完全是“单元测试”。
回答by Pascal Thivent
JAX-WS web services are annotated POJOs so you can unit testthem (in isolation) using a regular unit testing framework (JUnit, TestNG) and Mocks.
JAX-WS Web服务进行注释的POJO这样你就可以单元测试使用普通的单元测试框架(JUnit的,TestNG的),并嘲弄他们(隔离)。
回答by kopper
For functional testing - you can use tools like soapUI(but I don't recommend this option because tests created with this tool are really hard to maintain). Other option (recommended) is using JUnit tests in which you create the service + client and exercise service methods. In our project we use Apache CXFand it works very well. It also supports JAX-WS.
对于功能测试 - 您可以使用诸如soapUI 之类的工具(但我不推荐此选项,因为使用此工具创建的测试确实很难维护)。其他选项(推荐)是使用 JUnit 测试,您可以在其中创建服务 + 客户端并执行服务方法。在我们的项目中,我们使用 Apache CXF,它运行良好。它还支持 JAX-WS。
For unit testing - "regular" JUnit, since generated service is Plain Java Object.
对于单元测试 - “常规” JUnit,因为生成的服务是普通 Java 对象。
回答by rogerdpack
you can use Jersey to test end points: http://jersey.java.net/nonav/documentation/latest/test-framework.html
您可以使用 Jersey 来测试端点:http: //jersey.java.net/nonav/documentation/latest/test-framework.html

