单元测试构建文件

发布于 2024-07-19 08:32:21 字数 279 浏览 5 评论 0原文

单元测试构建文件的最佳策略是什么?

我问的原因是我的公司生产高度可靠的嵌入式设备。 软件补丁不是一种选择,因为分发它们需要我们的客户花费数千美元。 因此,我们有非常严格的代码质量程序(单元测试、代码审查、可追溯性等)。 这些程序正在应用于我们的构建文件(如果您必须知道的话,我希望遗憾的是自动工具),但感觉就像是黑客。

呃...项目编译...将构建文件标记为已审查和单元测试。

必须有更好的方法。 有想法吗?

What are the best policies for unit testing build files?

The reason I ask is my company produces highly reliable embedded devices. Software patches are just not an option, as they cost our customers thousands to distribute. Because of this we have very strict code quality procedures(unit tests, code reviews, tracability, etc). Those procedures are being applied to our build files (autotools if you must know, I expect pity), but if feels like a hack.

Uh... the project compiles... mark the build files as reviewed and unit tested.

There has got to be a better way. Ideas?

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

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

发布评论

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

评论(3

柠北森屋 2024-07-26 08:32:21

这是我们在跨十几个平台构建大型代码库(数百万行代码)时所采取的方法。

  • Makefile 更改由构建团队审核。这些人知道人们在我们的构建环境中容易犯的错误,并且当构建中断时他们是首当其冲的人,因此他们有动力去发现问题。
  • 最大限度地减少 Makefile 中需要的内容,从而减少出错的机会。 我们在 make 之上有一个层,用于生成 Makefile。 开发人员只需在更高级别的文件中使用标签来指示,例如给定的目标是共享库或单元测试。 通常,一个目标定义在一行上,然后在生成的 Makefile 中产生多个设置/目标。 类似的事情可以使用诸如 scons 之类的构建工具来完成,这些工具允许人们抽象出特定于平台的详细信息等内容,使目标变得非常简单。
  • 我们的构建工具的单元测试。该工具是用 Perl 编写的,因此我们使用 Perl 的 Test::More 单元测试框架用于验证该工具是否根据我们的更高级别文件生成了正确的 Makefile。 如果我们使用 scons 之类的东西,我会使用他们的测试框架
  • 我们的夜间构建/测试脚本的单元测试。我们有一组脚本,可以在每个平台上启动夜间构建,运行静态分析工具,运行单元测试,运行功能测试,并将所有结果报告给中央数据库。 我们单独测试各种脚本,主要使用 sh/bash 的 shunit2 单元测试框架/ksh/等。
  • 我们的构建/测试过程的端到端测试。我正在开展一个端到端测试,该测试在一个微小的源代码树上运行,而不是在我们的生产代码上运行,因为后者可能需要几个小时建造。 这些测试主要旨在验证我们的构建目标是否仍然有效,并将结果报告到我们的中央数据库中,即使在升级我们的代码覆盖工具或更改我们的构建脚本之后也是如此。

Here's the approach we've taken when building a large code base (many millions of lines of code) across more than a dozen platforms.

  • Makefile changes are reviewed by the build team. These people know the errors people tend to make in our build environment, and they are the ones who feel the brunt of it when a build breaks, so they're motivated to find issues.
  • Minimize what needs to go in a Makefile, so there are fewer opportunities for error. We have a layer on top of make, that generates the Makefile. A developer just has to indicate in the higher-level file, using tags, that for example a given target is a shared library or a unit test. Usually a target is defined on one line, which then results in multiple settings/targets in the generated Makefile. Similar things could be done with build tools like scons that allow one to abstract away things like platform-specific details, making targets very simple.
  • Unit tests of our build tool. The tool is written in Perl, so we use Perl's Test::More unit test framework there to verify that the tool generates the correct Makefile given our higher-level file. If we used something like scons instead, I'd use their testing framework.
  • Unit tests of our nightly build/test scripts. We have a set of scripts that start nightly builds on each platform, run static analysis tools, run unit tests, run functional tests, and report all results to a central database. We test the various scripts individually, mostly using the shunit2 unit-testing framework for sh/bash/ksh/etc.
  • End-to-end tests of our build/test process. I am working on an end-to-end test that operates on a tiny source tree rather than our production code, since the latter can take hours to build. These tests are mainly aimed at verifying that our build targets still work and report results into our central database even after, for example, upgrading our code coverage tool or making changes to our build scripts.
残花月 2024-07-26 08:32:21

让您的构建文件编译软件的已知版本(或者从构建角度来看类似的更简单的代码),并将使用新构建工具获得的结果与预期结果(使用经过验证的构建工具版本构建)进行比较)。

Have your build file to compile a known version of your software (or simpler piece of code that is similar from a build perspective) and compare the result obtained with your new build tools to a expected result (built with a validated version of the build tools).

却一份温柔 2024-07-26 08:32:21

在我的项目中,构建文件不会经常更改。 更重要的是,我可以重用早期项目中的构建文件,只更改一些变量(我将其移至易于识别的部分)。 这就是为什么对我来说不需要对构建文件进行单元测试。 这在其他项目中可能有所不同。

In my projects build-files don't change very often. Even more, I can reuse build-files from earlier projects, only changing some variables (that I moved to an easy to recognize section). That's why for me it is unneeded to unit-test the build-files. That can be different in other projects.

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