简体   繁体   English

使用JUnit自动测试Web服务

[英]Test automatically web services with JUnit

I have a lot of webServices that I want to test with Junit. 我有很多要通过Junit测试的webService。 For each webService I have between 5 and 40 tests to do, and writing those tests by hand take a lot of time and it is very tedious to do because they are almost the same. 对于每个webService,我需要进行5到40个测试,而手工编写这些测试会花费很多时间,而且做起来非常繁琐,因为它们几乎相同。

In fact, I send an xml request to my web service, get the response and compare it with the one expected. 实际上,我将xml请求发送到我的Web服务,获取响应并将其与预期的响应进行比较。 So for each test, I need only the webService URL, the body of the request and the response expected. 因此,对于每个测试,我只需要webService URL,请求的正文和预期的响应。

What is the best way to achieve this? 实现此目标的最佳方法是什么? Thanks 谢谢

I found a good way to do this. 我找到了一个很好的方法。 I use JUnit parameterized tests . 我使用JUnit参数化测试 This is a good tutorial to learn how to implement those tests. 是学习如何实施这些测试的很好的教程。

I use also generic methods that read a WSDL file and retrieve the types needed to do my tests. 我还使用通用方法来读取WSDL文件并检索进行测试所需的类型。 So now I have just one generic parameterized test for all my webServices, and parameters are paths of my WSDL files, input files and expected output files. 因此,现在我只有一个针对所有webService的通用参数化测试,参数是WSDL文件,输入文件和预期输出文件的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM