What are Google Test, Death Tests(什么是 Google 测试、死亡测试)
问题描述
我看到该功能的文档似乎非常重要,因为它位于 Google 测试概述功能中,并在:
https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests
I saw the documentation of that feature is seem pretty major since it's in Google Test overview features and detailed in:
https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests
它们看起来像标准的 assert() 但它们是 Google Test 的一部分,因此是一个 xUnit 测试框架.因此,我想知道使用这些死亡测试的真正用途或优势是什么.
They look like standard assert() but they're part of Google Test, so a xUnit testing framework. Therefore, I wonder what the real usage or advantage of using those death tests are.
推荐答案
断言是为了确认一个函数如果在当前进程中执行会导致程序终止(详细说明死亡测试是从一个允许测试继续进行的子进程,尽管死亡).这很有用,因为某些代码可以保证程序在失败时终止/中止(例如,如果存在不可恢复的错误),并且单元测试应确认函数遵守其记录的行为,而不管它可能是什么.
The assertion is there to confirm that a function would bring about program termination if it were executed in the current process (the details explains that the death test is invoked from a subprocess which allows the tests to continue despite the death). This is useful because some code may guarantee program termination / abortion on failure (e.g. if there was an irrecoverable error), and unit tests should confirm that a function adheres to its documented behavior, regardless of what that might be.
wiki 页面上的描述确实最好地解释了它:
The description on the wiki page really explains it best:
在许多应用程序中,如果不满足某个条件,断言可能会导致应用程序失败.这些确保程序处于已知良好状态的健全性检查会在某些程序状态损坏后尽早失败.如果断言检查了错误的条件,则程序可能会以错误的状态继续运行,这可能导致内存损坏、安全漏洞或更糟.因此,测试此类断言语句是否按预期工作至关重要.
In many applications, there are assertions that can cause application failure if a condition is not met. These sanity checks, which ensure that the program is in a known good state, are there to fail at the earliest possible time after some program state is corrupted. If the assertion checks the wrong condition, then the program may proceed in an erroneous state, which could lead to memory corruption, security holes, or worse. Hence it is vitally important to test that such assertion statements work as expected.
这篇关于什么是 Google 测试、死亡测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是 Google 测试、死亡测试
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
