软件测试速成
As software engineers, we want to write code that not only works, but works in every possible situation a user could find themselves in. Under any circumstance, we want our code to run the way we designed it to run, or at the very least communicate clearly what went wrong.
作为软件工程师,我们希望编写的代码不仅可以工作,而且可以在用户可能遇到的每种情况下工作。在任何情况下,我们都希望代码按照设计时的方式运行,或者至少清楚地沟通出了什么问题。
Enter testing.
输入测试。
Testing is the way we test our programs. Simple. The concept alone may be intuitive, but there’s a bit more nuance to how we design tests effectively and efficiently.
测试是我们测试程序的方式。 简单。 单独的概念可能很直观,但是我们如何有效地设计测试还有更多细微差别。
The great conflict of testing is that
测试的最大矛盾是
- Everyone wants their code to work.每个人都希望他们的代码能够正常工作。
- No one wants to write tests to ensure their code works. 没有人愿意编写测试来确保其代码正常工作。
To wiggle their way out of this dilemma, software engineers devised methods so that they could rigorously derive as much confidence in their programs as possible whilst consuming the least amount of energy.
为了摆脱困境,软件工程师设计了一些方法,以便他们可以在消耗最少能量的情况下,尽可能严格地对自己的程序产生信心。
The way I think of it, we have a spectrum of tests starting with the most effort and the most confidence in our code working, to very little effort and less confidence in our testing. We want to make tests intelligently so we can fall above the line, so we are getting enough confidence in our program with the least amount of effort.
按照我的想法,我们进行了一系列测试,从对代码工作的最大努力和最大信心开始,到对我们的测试的很少努力和信心不足。 我们希望智能地进行测试,以使我们能够脱颖而出,因此我们用最少的精力就可以对程序充满信心。
![A graph of where different testing methods fall on a scale of effort and accuracy](https://img-blog.csdnimg.cn/img_convert/c4b9786b2592ad423ea8dd7e1bb88e32.png)
Before software engineers got to systematic testing, I imagine they went through something similar to the following intuition:
在软件工程师进行系统测试之前,我想他们经历了类似于以下直觉的事情:
“Let’s just run our program and see if it works.” This is known as haphazard testing. When things started getting rough because they were ensuring little to no accuracy in their programs, they thought of something else.
“让我们运行我们的程序,看看它是否有效。” 这就是所谓的偶然性测试。 当由于无法确保程序的准确性而使事情开始变得艰难时,他们想到了其他事情。
“What if we tested everything?” This is called exhaustive testing. I made sure to say “what if” at the beginning because even if we were to just test a simple addition function exhaustively…
“如果我们测试了