使用Maven部署后如何运行测试? [英] How to run tests after deployment using Maven?

查看:221
本文介绍了使用Maven部署后如何运行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图决定如何为Java-EE Web应用程序创建一套验收测试。

I'm trying to decide how to create a set of Acceptance Tests for a Java-EE web application.

这是设置:Maven用于生成WAR文件并将其部署到Glassfish。在部署时,MySQL数据库模式将使用Hibernate(hbm2ddl = auto选项)从模型类自动更新。

Here's the setup: Maven is used to generate a WAR file and deploy it into Glassfish. On deployment, the MySQL database schema is automatically updated from model classes using Hibernate ("hbm2ddl=auto" option).

验收测试需要通过调用来测试部署的代码各种方法和检查结果如预期(*)。我们编写了一组额外的包来挂接到现有的系统中,所以接受测试应该显示如何将它们集成到现有的代码库中。

The Acceptance Tests need to test the deployed code by invoking various methods and checking the results are as expected(*). We wrote an additional set of packages to hook into an existing system so the Acceptance Tests should show how these can be integrated into the existing codebase.

(*)这可能听起来更像是单元/集成测试,但它们是接受测试,它们应该证明我们所做的工作,并且需要运行部署,所以有一个数据库。

(*) This may sound more like Unit/Integration Testing but they are Acceptance Tests in the sense that they should prove what we did works and they need to be run after deployment so there is a database in place.

从上面我现在的想法是使用JUnit来检查预期值等。我正在努力的一点是在部署之后调用这些测试。 部署是Maven的最后一个阶段,所以不知道这是否可行?

From the above, my current thinking is to use JUnit to check expected values etc. The bit I'm struggling with is how to invoke these tests after deployment. "deploy" is Maven's last phase so not sure if this is possible?

推荐答案

只是因为这个阶段被称为 deploy 并不意味着您必须使用它来部署应用程序进行测试。实际上,它只能用于将工件部署到maven存储库。请阅读 Maven生命周期阶段的说明,您将看到有一些阶段专门针对您的用例:

Just because that phase is called deploy doesn't mean that you have to use it for deploying your application for testing. In fact, it should only be used for "deploying" the artifact to a maven repository. Read through the description of the Maven lifecycle phases and you'll see that there are some phases dedicated to your use case:

pre-integration-test
integration-test
post-integration-test  

看看 Cargo Maven插件。它是将WAR文件部署到各种容器进行测试。他们绝对展示了您在网站上描述的用例的演示。我希望最终可以使用Cargo部署到您的容器(从之前的一个阶段,如预集成测试)

Have a look at the Cargo Maven plugin. It's made to deploy your WAR file to various containers for testing. They definitely show demos of use cases like the one you describe on your site. I would expect that ultimately, you can be using Cargo to deploy to your container ( from one of the earlier phases like pre-integration-test )

注意,Jenkins也有一个插件是Cargo插件的包装。所以你可以通过詹金斯做你需要的。另外请注意,您不需要像mvn clean deploy一样运行Jenkins构建作业。您可以有一个构建作业只运行集成测试,并且仅在成功时触发另一个部署作业。

Note, Jenkins also has a plugin that is a wrapper around the Cargo plugin. So you might do what you need via Jenkins. Also note, you don't need to run your Jenkins build job as mvn clean deploy. You could have one build job that just runs the integration tests, and fires another "deploy" job only when it succeeds.

这篇关于使用Maven部署后如何运行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆