Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

5.11 测试

我们如何知道应该什么时候停止调试呢?不错,在找到所有错误前,我们应该继续调试,或者尽力去做。我们如何知道已经找到了最后一个错误了呢?答案是没有办法。“最后一个错误”是程序员之间的笑话:这种东西是不存在的。对一个大程序来说,我们永远不会找到“最后一个错误”。因为在寻找错误的同时,我们还要忙于按照新需求修改程序。

除了调试以外,我们还需要一种系统地查找错误的方法。这被称为测试(test),我们将在7.3节、第10章的习题和第26章中详细介绍相关内容。基本上,测试是把一个巨大的、有系统地选择过的数据集输入给程序,然后把相关的结果与期望值进行比较。基于一组给定输入的一次程序运行被称为一个测试用例(test case)。实际程序可能会需要上百万个测试用例来进行测试。基本上,系统测试不可能靠人手工输入一个个测试用例。在介绍过后续几章内容并掌握了必要的工具后,我们再正式讨论测试。在此期间,我们需要谨记的是找到错误才是好的,这才是进行测试需要秉承的态度。看看下面的内容:

态度1:我比任何程序都聪明!我将击败这些@#$%^代码。

态度2:这部分代码我已经打磨了两周时间了。它是完美的。

你认为谁会找出更多的错误?当然,最好的情况是一个有经验的人带着一点“态度1”,沉着、冷静、耐心地对程序中所有可能出错的地方进行系统地检查。好的测试人员是非常难能可贵的。

我们会尽量系统地选择测试用例,一般会包括正确和不正确的输入数据。7.3节中会给出第一个示例。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252