什么是 Google 测试、死亡测试

发布于 2024-09-19 02:25:10 字数 385 浏览 6 评论 0原文

我看到该功能的文档似乎非常重要,因为它位于 Google 测试概述功能中,并在以下位置详细说明:
https://github.com/google/googletest/ blob/master/docs/advanced.md#death-tests

它们看起来像标准 assert() 但它们是 Google Test 的一部分,因此是 xUnit 测试框架。因此,我想知道使用这些死亡测试的真正用途或优势是什么。

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

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.

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

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

发布评论

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

评论(2

影子是时光的心 2024-09-26 02:25:10

断言的作用是确认如果某个函数在当前进程中执行,该函数将导致程序终止(详细信息解释了死亡测试是从子进程调用的,该子进程允许测试在死亡的情况下继续进行)。这很有用,因为某些代码可以保证程序在失败时终止/中止(例如,如果存在不可恢复的错误),并且单元测试应确认函数遵循其记录的行为,无论可能是什么。

维基页面上的描述确实最好地解释了这一点:

在许多应用程序中,如果不满足条件,某些断言可能会导致应用程序失败。这些健全性检查确保程序处于已知的良好状态,但在某些程序状态损坏后会尽早失败。如果断言检查了错误的条件,则程序可能会在错误状态下继续运行,这可能会导致内存损坏、安全漏洞或更糟糕的情况。因此,测试此类断言语句是否按预期工作至关重要。

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.

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.

苏大泽ㄣ 2024-09-26 02:25:10

我认为您链接中的介绍很好地解释了这一点:

在许多应用程序中,如果不满足条件,某些断言可能会导致应用程序失败。这些健全性检查确保程序处于已知的良好状态,但在某些程序状态损坏后会尽早失败。如果断言检查了错误的条件,则程序可能会在错误状态下继续运行,这可能会导致内存损坏、安全漏洞或更糟糕的情况。因此,测试此类断言语句是否按预期工作至关重要。

由于这些前提条件检查会导致进程死亡,因此我们将此类测试称为死亡测试。更一般地说,任何检查程序是否以预期方式终止的测试也是死亡测试。

其中哪一点没有意义?

I thought the introduction in your link explained it fairly well:

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.

Since these precondition checks cause the processes to die, we call such tests death tests. More generally, any test that checks that a program terminates in an expected fashion is also a death test.

What bit of that doesn't make sense?

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