[英]Unit testing a web service client from NetBeans
I have a project that contains both the ws client and service (JAX-WS).我有一个包含 ws 客户端和服务(JAX-WS)的项目。 Is there a way of having the ws deploy during automated testing such that I can have my client tests encompass the calls to the service?有没有办法在自动化测试期间部署 ws,以便我可以让我的客户端测试包含对服务的调用?
Obviously this would require deployment to an application server... or is this kind of testing ill-advised?显然这需要部署到应用程序服务器......或者这种测试不明智?
I found a suitable solution to this problem.我找到了解决这个问题的合适方法。 Using embedded Tomcat (7.0.11), I was able to successfully deploy my web-service programmatically during the running of the unit test.使用嵌入式 Tomcat (7.0.11),我能够在单元测试运行期间以编程方式成功部署我的 Web 服务。
tomcat = new Tomcat();
tomcat.setBaseDir(".");
tomcat.setPort(8084);
tomcat.addWebapp("/", System.getProperty("user.dir") + "/build/web");
tomcat.setHostname("localhost");
tomcat.enableNaming();
tomcat.start();
This approach suited me well as I wanted to automate the testing of a web-service client.这种方法很适合我,因为我想自动化 Web 服务客户端的测试。 As Piyush pointed out, soapUI is a perfect way to perform integration testing.正如Piyush所指出的,soapUI 是执行集成测试的完美方式。
Edit编辑
If you are using context.xml
you will need to define it like so:如果你使用context.xml
你需要像这样定义它:
Context ctx = tomcat.addWebapp("/", System.getProperty("user.dir") + "/build/web");
File contextFile = new File("META-INF/context.xml");
ctx.setConfigFile(contextFile);
How are you generating your service?你是如何产生你的服务的? What kind of Web Services are they?它们是什么类型的 Web 服务? Isn't your generated service a regular POJO?您生成的服务不是常规 POJO 吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.