在Maven下对多个Spring Boot应用程序进行端到端集成测试 [英] End to end integration test for multiple spring boot applications under Maven

查看:149
本文介绍了在Maven下对多个Spring Boot应用程序进行端到端集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven构建的验证阶段为多个Spring引导应用程序运行端到端集成测试的推荐方法是什么?

What is the recommended way of running an end to end integration test for multiple Spring boot applications in the Maven build's verify phase?

基本上,我有一个多模块Maven项目,其中几个模块是独立的spring boot应用程序.这些单独的应用程序具有自己的数据源配置,与JMS队列的集成流等.例如,应用程序A会轮询数据库以查找事件,当事件发生时,它将生成数据的JSON文件并放入JMS队列上的一条消息.应用程序B正在轮询JMS队列,因此接收消息,读取文件,使用另一个数据库进行一些处理,然后将消息放在另一个队列中.然后,应用程序C将接收该消息,等等,等等.

Basically, I have a multi-module Maven project where several modules are separate spring boot applications. These separate applications have their own configuration for data sources, integration flows with JMS queues, etc. For example, application A will poll a database for an event, and when that occurs, it produces a JSON file of data and puts a message on a JMS queue. Application B is polling the JMS queue, so picks up the message, reads the file, does some processing using another database, and puts a message on a different queue. Application C will then pick up that message, etc, etc.

我已经为各个应用程序设置了集成测试;它们在Maven故障安全插件下运行.但是,我想在Maven下端到端地集成测试整个系统.我已经在专为此任务的项目中设置了一个单独的模块,因此希望该模块的验证构建阶段可以使用其他相关模块进行端到端测试.

I have set up integration tests for the individual applications; these run under the Maven failsafe plugin. However, I would like to integration test the whole system, end to end, under Maven. I have set up a separate module in the project dedicated to this task, and so would like the verify build phase of this module to do the end to end testing using the other dependent modules.

是否有这样做的最佳实践方法?我看到3种可能的方式:

Is there a best practice way of doing this? I see 3 potential ways:

  1. 将每个应用程序的配置加载到相同的应用程序上下文中.但是,由于存在多个数据源等,因此会产生冲突,因此必须手动配置所有这些数据源,才能启用端到端集成测试-因此,这对我来说似乎是错误的.
  2. 将每个应用程序作为一个单独的进程启动-如何在测试模块构建停止/崩溃/崩溃等情况下正确地跟踪它们并确保它们被关闭?
  3. 是否有一种方法可以在同一过程中轻松加载单独的Spring Boot应用程序,每个应用程序都有自己的配置上下文?这似乎是最明智的选择.关于Maven构建/故障安全插件是否有任何考虑因素?
  1. Load each application's configuration into the same application context. However, because of multiple data sources etc, this creates conflicts, and so these data sources would all have to be manually configured just to enable end to end integration testing - so this seems wrong to me.
  2. Launch each application as a separate process - how then to properly keep track of them and make sure they get shut down if the test module build stops/crashes/etc?
  3. Is there a way to easily load separate spring boot applications, each with its own configuration context, in the same process? This would seem to be the most sensible option. Are there any considerations in respect of the Maven build/failsafe plugin?

推荐答案

很好的问题!我自己会对其他人的回答感兴趣.我会发表我的看法.

Very nice question! I would by myself be interested what other people answer. I'll share my opinion.

根据我的理解,首先您应该知道要测试的内容. 集成测试应该与至少一部分应用程序一起使用,并确保您开发的组件在半真实的环境中可以正常工作.看来您已经做到了.

In my understanding first of all you should know what exactly you want to test. Integration tests should work with an application of at least with a part of it and ensure that the component you've developed works properly in a semi-real environment. It seems like you've already done that.

现在,关于系统测试(我有意区分集成测试和系统测试).这些应该模仿"质量检查人员:)因此,他们将系统视为黑匣子.他们不能调用任何内部API并运行真实流. 端到端测试IMO属于此类.

Now, regarding system tests (I intentionally differentiate between integration and system tests). These should 'mimic' QA guys :) So, they treat a system as a black box. They can't invoke any internal APIs and run real flows. End-to-end tests IMO fall into this category.

在这种情况下,您希望将它们与生产环境中部署的系统和生产环境中的类路径进行比较.

In this case you would like to check them against the system deployed like in production, with the classpath like in production.

所以我真的不像您一样相信选项1.

So I don't really believe in option 1 just like you.

关于选项3,我不确定它是否也是一个好的解决方案. 即使您在不同的应用程序上下文中运行您的内容(我不太了解Spring引导,因此我也无法从技术上对此进行评论),但据我所知,它们将在运行时共享相同的类路径,因此您可能有风险在您的第三方之间发生冲突(尽管我知道spring boot本身定义了很多jar版本,但您知道我的意思),尤其是当您仅升级一个模块并可能更改依赖项时. 因此,当您按照这种方法运行时,您实际上并不真正知道内存中到底运行了什么.

Regarding the option 3 I'm not sure whether its a good solution as well. Even if you run your stuff with different application contexts (I don't know much Spring boot so I can't technically comment on it), in my understanding they will share the same classpath in runtime, so probably you're in risk to get clash among your thirdparties (although I know that spring boot defines a lot of versions of jars by itself, you know what I mean) especially when you upgrade only one module and probably change the dependencies. So you don't really know what exactly runs in memory when you run follow this approach.

因此,对于端到端测试,我会选择选项2. 关于同步,可能的选择是在应用程序级别结合操作系统级别的进程状态跟踪来实现一些逻辑. 我要评论的另一点是,一般而言,端到端测试仍然是功能测试(它们检查系统的功能行为),因此,一般而言,您不应该在每个测试中都检查系统崩溃.如果检查每个流的系统崩溃,这些测试将太慢. 当然,您可以维护一个相对较小的测试套件来检查极端情况.

So, for end-to-end tests, I would go with option 2. Regarding the synchronization, probably the option would be implementing some logic at the application level in conjunction with process state tracking at the level of operating system. One more point I would like to comment on is that end-to-end tests in general are still functional testing (they check the functional behavior of the system) so in general you shouldn't check system crashes there in each test. If you check the system crash for each flow, these tests will be too slow. Of course you can maintain one relatively small test suite to check corner cases as such.

希望这会有所帮助

这篇关于在Maven下对多个Spring Boot应用程序进行端到端集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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