如何自动化构建、部署和测试 Java Web 应用程序?
现在我有一个 web java 项目,只需将ear存档复制到服务器目录(全部使用Ant)即可自动构建并部署到JBoss。
我需要的是一种机制,不仅可以自动部署应用程序,还可以验证应用程序是否已成功部署并对其运行 HttpUnit 测试。
问题是如何自动监视部署过程以等待部署完成后才运行测试。 所以我想“一键”构建、部署、运行测试(我使用 Cruise Control)。
对于任何有关解决问题的建议,我将不胜感激。
For now I have a web java project which builds automatically and deployed to the JBoss by just copying ear archive to server dir (all using Ant).
What I need is a mechanism how to no only automatically deploy application, but also to verify if application deployed successfully and run HttpUnit tests on it.
The problem is how to automatically monitor deployment process to wait for the moment when deployment is finished and only after that run tests. So I want to build, deploy, run tests in "one click" (i use Cruise Control for that).
I would be appreciate for any suggestion about resolving the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里需要启动一个容器并从构建脚本部署应用程序,然后根据部署的应用程序运行测试。 这是集成测试、端到端/功能测试、ui 测试的典型需求。
问题是我们不能只是“一劳永逸”地启动容器并运行测试任务/目标。 我们需要等待应用程序部署后才能运行测试,这需要一些时间。 为了确保我们可以在一切准备就绪时运行测试,构建必须启动容器并以阻塞方式部署应用程序。
这正是Cargo 的意义所在。 Cargo 是一个 Java API,用于启动/停止容器和部署应用程序。 它提供了上述逻辑,并且可以从 Java、Ant 或 Maven 中使用。
如果您使用 Maven,构建生命周期已经包含了“集成测试”阶段的内容。 此阶段通常用于...集成测试,并由“集成前测试”和“集成后测试”阶段包裹。 您可以在此处插入 Cargo 启动/停止目标。 如果你使用Ant,你可以使用cargo的ant任务。
Mavan Jetty 插件配置指南中描述了另一个基于 Maven 的选项。 这个想法与上面完全相同,只是你使用jetty插件而不是cargo在“集成前测试”期间启动jetty并在“集成后测试”期间停止它。
The need here is to start a container and to deploy an application from a build script before to run tests depending on the deployed application. This is a typical need for integration tests, end-to-end / functional tests, ui tests.
The problem is that we can't just "fire and forget" the launch of a container and run the test task/goal. We need to wait for the application to be deployed before to run the tests and this takes some time. To be sure we can run tests when things are ready, the build has to start the container and deploy the application in a blocking way.
This is exactly what Cargo is about. Cargo is a Java API to start/stop your container and deploy your application. It provides the logic described above and can be used from Java, Ant or Maven.
If you are using Maven, the build life cycle already includes something for you with the "integration-test" phase. This phase is typically used for... integration tests and is wrapped by the "pre-integration-test" and "post-integration-test" phases. This is where you would plug Cargo start/stop goals. If you are using Ant, you can use cargo's ant task.
Another option based on the maven is described in the Mavan Jetty Plugin Configuration Guide. The idea is exactly the same as above except that you use the jetty plugin instead of cargo to start jetty during the "pre-integration-test" and stop it during the "post-integration-test".
创建一个基测试类,所有其他测试都派生自该基测试类。 它必须是抽象的,以便自动单元测试收集器不会尝试运行它。
在该类中,将此代码添加到 setUp():
checkIsDeployed
必须是静态的。Create a base test class from which all other tests derive. It has to be abstract so the automatic unit test collector doesn't try to run it.
In that class, add this code to setUp():
checkIsDeployed
must be static.另一种选择是使用 JBoss Server Ant 任务。
这些任务的好处是它们会阻塞直到 JBoss 完全启动,因此不需要轮询。 如果 JBoss 未能在要求的超时时间内启动,它们也会失败,并且如果由于某些错误而无法关闭 JBoss,它们也会在 JVM 关闭时尝试关闭 JBoss。 我相信这些任务用于 JBoss 测试套件。
我也听说过有关 Cargo 的好消息。 这样做的好处是您的构建脚本不是特定于 JBoss 的。 据我所知,我认为 JBoss Cargo 插件是由一些 JBoss 人员维护的。
Another option is to use the JBoss Server Ant Tasks.
The nice thing about these tasks is that they will block until JBoss is fully started, so there is no polling required. They will also fail if JBoss fails to start in the required timeout, and will attempt to shut JBoss down at the JVM shutdown if you are unable to because of some error. I believe these tasks are used for the JBoss testsuite.
I've also heard good things about Cargo. The benefit of it is that your build scripts are not JBoss specific. I think the JBoss Cargo plugin is maintained by some JBoss guys, as far as I know.
您可以考虑使用 hudson 构建引擎:https://hudson.dev.java.net/帮助您在特定时间触发事件。
我知道 hudson 可以用来运行单元测试,并且可以通过调用 ant 来实现自动部署。
卡尔
You could consider using hudson build engine: https://hudson.dev.java.net/ to help you fire off events at specific times.
I know hudson can be used to run unit tests and automatic deployment could be achived by calling ant.
Karl