生产发布代码中的单元测试?

发布于 2024-08-02 02:49:10 字数 1432 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

时光是把杀猪刀 2024-08-09 02:49:10
  1. 绝对地。 如果我们的构建通过了单元测试套件,那么它就会被标记为生产编号的候选者
  2. 。部署不包括测试,也不包括支持库(例如单元测试库、模拟等)。

以上是我的一般规则(我通常部署对于非技术用户)。 不过,我确实有一个例外,它是一个编程实用程序,使用约 130 个测试脚本进行了单元测试。 由于测试脚本兼作示例,因此我将它们与生产版本一起部署,从而增强了现有文档。

使用开源代码部署测试绝对是值得的。 它允许人们玩、修改和提交补丁,同时能够运行成功通过的测试以允许发布原始工件。

  1. Absolutely. If our build passes the unit test suite then it's tagged and a candidate for production
  2. No. Deployments don't include tests nor the supporting libraries (e.g. unit test libraries, mocking etc.)

The above is my general rule (I'm usually deploying to non-technical users). However I do have an exception, which is a programming utility that is unit tested with ~130 test scripts. Because the test scripts double as examples, I deploy those along with the production release, and consequently they enhance the existing documentation.

Deploying tests with open-source code is definitely worthwhile. It allows people to play with, modify and submit patches, whilst being able to run the tests that passed successfully to permit the original artifact to be released.

泅渡 2024-08-09 02:49:10

是的,是的,发布版本和调试版本之间的应用程序行为可能有所不同,因此作为发布过程的一部分,发布版本必须通过其所有单元测试。

Yes and Yes, application behaviour can be different between release and debug builds, hence as part of the release process the release build has to pass all its unit tests.

终陌 2024-08-09 02:49:10
  1. 是的,当然! 单元测试在所有构建配置上运行。

  2. 单元测试始终完好无损,但这并不意味着交付的程序集依赖于与测试相关的任何内容。
    测试始终在并行程序集中(在同一构建环境中)编写,然后测试生产程序集。 并行程序集未发货,因为它仅包含测试。

  1. Yes of course! Unit tests run on all build configurations.

  2. Unit tests are always intact but this does not mean that shipped assemblies are dependent on anything relating to the tests.
    Tests are always written in a parallel assembly (in the same build environment) that then tests the production assembly. The parallel assembly is not shipped as it only contains the tests.

孤君无依 2024-08-09 02:49:10
  1. 是的,请记住也必须捕获的经典“带有副作用的断言”错误。 但这不需要像调试构建那样频繁地进行,调试构建应该每天进行一次完整的测试。
  2. 通常,单元测试位于不同的翻译单元和不同的项目中,因此主项目的发布版本根本不会触及它们。 如果您的单元测试与测试代码位于相同的翻译单元中,则可以使用条件编译将它们从版本中排除。
  1. Yes, remember the classic "Assert with side-effects" error that must be caught as well. But this one doesn't need to be done as often as the debug build, where a complete test should be done every day.
  2. Typically unit-tests are in different translation units and in a different project, so that a release build of the main project does not touch them at all. If your unit-tests are in the same translation units as the tested code though, you can use conditional compilation to exclude them from releases.
白首有我共你 2024-08-09 02:49:10

取决于项目。 第 1 点是的。遵循这样的原则:所有内容都应该检查到源代码控制中,并且应该很容易让新开发人员上手。 让它们成为代码库的一部分。 新人可以检查并运行测试。

它们是否部署到生产中是另一个问题。 我还没有参与过需要他们的项目。 Rails 的部署模型(通常)只是在生产机器上检查整个项目,所以是的,它们就在那里。 Java/Maven 项目有一个完整的构建/打包步骤,并且通常在构建最终的 .war 文件时可以删除单元测试。

不管怎样,你都不希望他们跑。 在今天的环境中,它们是否位于那里并不重要——内存和磁盘都很便宜,这真的不是问题。 我听说过这样的论点:您不希望在生产服务器上运行测试代码,这样就不会有运行的风险,但我还没有听说过这种情况真的会发生的情况。

Depends on the project. Yes to number 1. Following the principal that everything should be checked into source code control and it should be simple to get a new developer going. Make them part of the codebase. New people can do a check out and run the tests.

Whether they are deployed to production is a different issue. I haven't worked on a project that needed them there. Rails' deployment model is (generally) simply a check-out of the whole project on a production machine, so yes they are there. Java/Maven projects have a whole build/packaging step, and generally unit tests can-- and are-- removed when building the final .war file.

Either way, you don't expect them to run. In today's environment, it doesn't really matter if they site there-- memory and disk are so cheap it's really not an issue. I have heard the argument that you don't want the test code on the production server so that there's no risk that it will get run, but I haven't heard of a scenario when this would really happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文