关于如何获取测试 jar 来运行单独的测试战争的指针(也许与货物?)
让我解释一下我的一些限制。
我们有一场战争,其中有 CXF Soap 服务和 Spring MVC REST 服务。 CXF 和 Spring MVC 实现都在一个单独的 jar 中,并作为依赖项引入。 REST 服务在其项目中具有单元测试。
我想知道是否有任何方法可以在 REST jar 中执行“mvn clean test”之类的操作时设置本地版本的 war,然后运行单元测试。因此,当构建像 Hudson 这样的东西或进行发布时,不必有任何解决方法(例如部署快照耳朵或手动运行局部战争)?我见过在战争期间使用货物进行测试时这样做的,但当测试与战争分开时则没有。
现在,我们将把测试放入一个单独的 jar 中,但这仍然不理想,就好像在发布过程中出现问题一样,这意味着 REST jar 和 war 已经发布了。我更愿意按照上述方式进行操作,并在与 REST 服务相同的项目中进行测试。
如果有人有任何可以帮助解决此问题的指示、文档或示例,我们将不胜感激。
Let me explain some of my constraints.
We have a war that has a CXF Soap service and a Spring MVC REST Service. Both the CXF and Spring MVC implementations are in a separate jar and are brought in as dependencies. The REST service has its unit tests in its project.
I was wondering if there was any way to, while doing something like 'mvn clean test' in the REST jar, to have a local version of the war set up and then run the unit tests. Thus, when building in something like Hudson or doing releases, there won't have to be any workarounds (such as deploying a snapshot ear or running a local war manually)? I've seen this done when the tests are within the war using cargo, but not when the tests are separate from the war.
Right now, we're going to take the tests out into a separate jar but that's still not ideal as if something happens to go wrong during a release, that'd mean the REST jar and war were already released. I'd prefer do it the above way, with the tests in the same project as the REST service.
If anyone has any pointers or doc or examples that could help with this, it would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
老实说,我不确定我是否理解所有的限制。无论如何,推荐使用 Maven 实现集成测试的方法是将它们放在一个单独的模块中(这更容易,特别是如果被测模块也有单元测试),这取决于 war/ear 下的情况。测试并执行以下操作:
pre-integration-test
阶段启动容器并部署 war/earintegration-test
期间运行测试 在期间停止容器>post-integration-test
对于步骤 #1 和 #3,我个人使用 Cargo。对于第 2 步,首选使用 Maven Failsafe 插件 (因为如果测试失败它不会停止构建)。至少,这是我使用的,并且我已经使用下面的资源来构建我的设置。
另一种方法是从测试中启动/停止嵌入式容器。例如,这可以通过 Jetty 实现,请参阅 嵌入 Jetty 和 使用 Jetty 进行单元测试 Servlet。
资源
Honestly, I'm not sure I understood all the constraints. Anyway, the recommended way to implement integration tests with Maven is to put them in a separate module (that's much easier, especially if the module under test also have unit tests) that depends on the war/ear under test and to:
pre-integration-test
phaseintegration-test
post-integration-test
For the steps #1 and #3, I personally use Cargo. For the step #2, using the Maven Failsafe Plugin is the preferred option (because it won't stop the build if a test fail). At least, this is what I use and I have used the resources below to build my setup.
An alternative approach would be to start/stop an embedded container from the tests. For example, this is doable with Jetty, see Embedding Jetty and Unit Test Servlets with Jetty.
Resources
Maven 还有集成测试阶段。使用 maven-jetty-plugin 启动容器并部署应用程序。然后运行集成测试。
更新
测试不能位于 jar 文件中。 Maven Surefire 插件无法运行它们。这些测试是您运行集成测试的项目的一部分。测试好的war文件可以设置为依赖库。它将被下载、部署并运行集成测试。
Maven has also integration-test phase. Use maven-jetty-plugin to start container and deploy application. Then run your integration test.
Update
Tests cannot be in a jar file. Maven surefire plugin could not run them. The tests are part of the project where you run integration test. The tested war file can be set as dependency library. It will be downloaded, deployed and the you run integration tests.