像往常一样对 docker 容器或 dockerize 测试运行测试? [英] Running tests as usual against docker containers or dockerize tests?

查看:11
本文介绍了像往常一样对 docker 容器或 dockerize 测试运行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Docker 新手,正在阅读 Docker.这是在独立且可重现的标准化配置中测试系统的好方法(如果操作正确).

I'm new to Docker and was reading up on Docker. It's a great way to test systems in a self contained and reproducible standardized configuration (when done correctly).

但是,在我阅读的所有内容中,似乎并没有过多强调应该如何使用 docker 容器进行测试.docker 用于包含"基础设施和应用程序(代码),以便于测试(以及部署).但有时测试代码库很大,也不是那么简单.一个人可以有一个测试代码库用于 API 测试,另一个用于 UI 等.

However, in all the things I've read, there doesn't seem to be too much emphasis on how the testing should occur with docker containers. The docker is used to "contain" the infrastructure and application (code) for easy testing (as well as deployment). But sometimes test codebases are be large and not so simple too. And one can have a test codebase for API tests, another for UI, etc.

测试 Docker 容器/应用程序/基础设施的部署的标准做法是什么,或者应该是什么?应该:

What is or should be (as determined at some point) the standard practice for testing docker containers/deployments of your applications/infrastructure? Should:

  • 测试代码以旧的传统方式部署,作为您从某个地方提取的文件存储库,然后在 Jenkins 服务器/从属或本地主机上运行以进行开发/QA 测试/调试,测试针对 docker 容器中的应用程序?
  • 将整个测试代码库 dockerize 为一个独立的容器,然后使用该容器针对具有应用代码/系统基础架构的其他容器启动/执行测试?
  • 将测试组合为各个 docker 容器本身的一部分,以便在需要时/根据需要运行.但我认为这仅适用于真正与包含匹配应用程序代码的容器配对的单元测试.集成、UI、系统级测试与系统内应用模块的关联不同.

我能想到的使 dockerizing 测试可能有用的唯一原因是它是一个容器,包含您需要的所有测试和匹配的测试基础设施(所有测试平台/语言依赖项),因此可以部署和运行测试与匹配的应用程序代码容器一起在任何地方.无需在需要时/根据需要设置测试基础架构.但似乎没有人在博客上写过这样的 dockerized 测试.

The only reason I can think of that make dockerizing tests perhaps useful is that it's a single container with all the tests you need and the matching test infrastructure (all the test platform/language dependencies) so that one can deploy and run tests anywhere together with the matching app code containers. Saves one from having to set up test infrastructure when/as needed. But no seems to have blogged about such a thing for dockerized tests.

推荐答案

我更喜欢您的选项 (3),即在生产可部署工件(docker 映像)中包含测试代码

I prefer your option (3) i.e. to include test code in the production deployable artifact (the docker image)

将引用 Alister Scott-automation-conference/2015/presentations#Day1Presentation5" rel="nofollow">GTAC 2015 我参加了:

Will quote Alister Scott from GTAC 2015 which I attended:

不要害怕向您的应用添加不符合功能目的的可测试性特定功能.我最近不得不在我的车上安装新轮胎,并意识到很多轮胎都具有称为胎面指示器的可测试性功能.这些没有功能性目的

Don’t be afraid to add testability specific features to your app that don’t serve a functional purpose. I recently had to get new tyres on my car and realized that a lot of tyres have testability features called tread indicators. These don’t serve a functional purpose

对于集成和 e2e 测试,即需要使用超过 1 个 docker 映像的测试,我更喜欢 CI工具,通过 docker-compose 和用于这些测试的单独 git repo 进行编排创建大型测试所需的所有容器.同样,使用的 docker 图像 应该与生产环境完全相同,除了 不同的是配置(例如环境变量),使测试指向测试数据和/或暂存服务.

For integration and e2e tests, i.e. tests that require more than 1 docker image to be used, I prefer CI tool that, through docker-compose, and a separate git repo for these tests, orchestrates the creation of all containers that are needed for the larger test. Again the docker images used should be the exact same as for production except what varies is the configuration (e.g. environment variables) that make the tests point to test data and/or staging services.

这篇关于像往常一样对 docker 容器或 dockerize 测试运行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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