c++ - 编写测试套件的指南

标签 c++ testing design-guidelines

<分区>

为 C++ 项目编写测试套件的最佳实践/指南是什么?

最佳答案

这是一个非常宽泛的问题。对于单元测试和测试驱动开发 (TDD),此 from Microsoft 上有一些有用的(如果部分内容有点白)指南- 如果不适用,您可以忽略特定于 Visual Studio 的建议。

如果您正在寻找有关系统或性能测试的指导,我会澄清您的问题。 docs for Boost.Test 中有一个更广泛的合理理由。 .

There are several unit testing best practices to review before we close. Firstly, TDD is an invaluable practice. Of all the development methodologies available, TDD is probably the one that will most radically improve development for many years to come and the investment is minimal. Any QA engineer will tell you that developers can't write successful software without corresponding tests. With TDD, the practice is to write those tests before even writing the implementation and ideally, writing the tests so that they can run as part of an unattended build script. It takes discipline to begin this habit, but once it is established, coding without the TDD approach feels like driving without a seatbelt.

For the tests themselves there are some additional principals that will help with successful testing:

Avoid creating dependencies between tests such that tests need to run in a particular order. Each test should be autonomous.

Use test initialization code to verify that test cleanup executed successfully and re-run the cleanup before executing a test if it did not run.

Write tests before writing the any production code implementation.

Create one test class corresponding to each class within the production code. This simplifies the test organization and makes it easy to choose where to places each test.

Use Visual Studio to generate the initial test project. This will significantly reduce the number of steps needed when manually setting up a test project and associating it to the production project.

Avoid creating other machine dependent tests such as tests dependent on a particular directory path.

Create mock objects to test interfaces. Mock objects are implemented within a test project to verify that the API matches the required functionality.

Verify that all tests run successfully before moving on to creating a new test. That way you ensure that you fix code immediately upon breaking it.

Maximize the number of tests that can be run unattended. Make absolutely certain that there is no reasonable unattended testing solution before relying solely on manual testing.

关于c++ - 编写测试套件的指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3978275/

相关文章:

c++ - 如何截断boost日志格式表达式

c++ - Lua 访问表的键和值

c++ - 如何通过自己的中心旋转所有对象,然后将它们平移到真实位置(它不起作用)

java - 使用 Robolectric,如何测试沿 POST *请求* 发送的 JSON 值

css - 使用内联 CSS 在外部样式表指定的 block 周围定位元素的最佳方法是什么?

android - ImageButton 的 Material Design 指南是什么?

python - 在 C++ 中嵌入 Cython 类方法

Android ExampleInstrumentedTest 口味失败

android - 在 Android 上同时将数据保存在内存和数据库中的最佳实践

ruby-on-rails - 如何确保我正在测试所有内容,我拥有所有功能并且只有旧代码的那些功能?