我有一个包含ws客户端和服务(JAX-WS)的项目。有没有办法在自动化测试期间部署ws,以便我可以让我的客户端测试包含对服务的调用?
显然这需要部署到应用服务器......或者这种测试是不明智的?
答案 0 :(得分:2)
我找到了解决这个问题的合适方案。使用嵌入式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();
这种方法很适合我,因为我想自动测试Web服务客户端。正如 Piyush 所指出的,soapUI是执行集成测试的完美方式。
修改强>
如果您使用context.xml
,则需要按以下方式定义:
Context ctx = tomcat.addWebapp("/", System.getProperty("user.dir") + "/build/web");
File contextFile = new File("META-INF/context.xml");
ctx.setConfigFile(contextFile);
答案 1 :(得分:1)