什么是 Google 测试、死亡测试

What are Google Test, Death Tests(什么是 Google 测试、死亡测试)

本文介绍了什么是 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 测试、死亡测试

基础教程推荐