如何使用Docker测试微服务中的集成层

huangapple go评论86阅读模式
英文:

How to test integration layer with microservices in docker

问题

我的项目是用Java编写的,与一个作为独立Docker容器启动的Elasticsearch一起工作。

我们当前的集成/组件测试是用python编写的,它们会启动我们的应用程序和Elasticsearch作为不同的Docker容器,运行测试,然后关闭这两个容器。

我认为将这些测试重写成java会更好,因为在整个项目中只使用一种语言对开发人员来说更容易,而且你将获得IDE支持。但在这种情况下,不清楚如何从Java测试中运行一个Docker容器以便对其进行测试。

英文:

My project is written in Java and works with an elastic search that starts as a separate docker container.

Our current integration/component tests are written in python, they start our app and elastic search as different docker containers, runs tests, and shuts down both of the containers.

I think it'll be much better to rewrite these tests on java because it's easy for developers when you have a single language throughout a project + you'll get and IDE support. But in this case, it's not clear how to run a docker container from Java test in order to test against it.

答案1

得分: 1

以下是已翻译的部分:

你的问题可以分解为以下步骤:

  1. 设置环境
  2. 运行集成测试
  3. 拆除设置

对于步骤2,你重新编写Java测试的想法确实是有道理的。

然而,对于设置和拆除,逻辑可能不一定在Java中(我更倾向于不在Java中)。原因是有各种各样的工具可用于Docker管理,可以处理步骤1和步骤3,这比通过Java来做要强大得多。

即使使用一个简单的Docker Compose文件,我也可以做到以下事情:

  1. 为Elasticsearch创建容器
  2. 为具有对Elasticsearch依赖的应用程序创建容器
  3. 为具有对应用程序依赖的运行Java测试创建容器

Docker Compose可以作为某个脚本的一部分运行,在超时后拆除设置,或者只是通知开发人员超时,让他们有机会调试和解决问题。

注意:这是一个高层次的概览,没有深入到更小的细节。请不要将其视为100%完整/正确。

英文:

Your problem can be broken down into following steps:

  1. Setup the environment
  2. Run integration tests
  3. Tear down the setup

Your thought process of rewriting tests in java does make sense for step-2.

However for setup and tear down, the logic may or may not be in java (I would prefer not). The reason is that there are various tools available for docker management that would take care of step-1 and step-3 which would be much more powerful than doing this via Java.

Even with a simple docker compose file I can do the following:

  1. Create container for elastic search
  2. Create container for app with dependency on elastic search
  3. Create container for running java tests with dependency on app.

The docker compose can run as part of some script that would tear down the setup after a timeout or just notify timeout to the developer giving him the control to debug and solve the issue/s.

Note: This is high level view without going into the smaller details. Please don't consider this as 100% complete/correct.

huangapple
  • 本文由 发表于 2020年7月21日 22:52:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63017211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定