现在的位置: 首页 > 综合 > 正文

为什么测试如此重要?

2019年05月13日 ⁄ 综合 ⁄ 共 3282字 ⁄ 字号 评论关闭

一些对程序员可能有用的话,翻译自 《Squeak By  Example》chap 5 SUnit

 

1. The interest in testing and Test Driven Development is not limited to Squeak or Smalltalk。

强调了SmallTalk对测试非常注重。

 

2. Automated testing has become a hallmark of the Agile software development movement, and any software developer concerned with improving software quality would do well to adopt it。

自动化测试已成为敏捷软件开发中的质量保证,任何关心软件质量的软件开发者需要对之进行关注。

 

3. eXtreme Programming, by making testing a core practice and by emphasizing automated tests, has helped to
make testing productive and fun, rather than a chore that programmers dislike.

极限编程,通过将测试至于核心开发活动地位以及强调自动测试,已经成功的帮助测试成为一个多产与有趣味的开发活动。

 

4. SUnit is valuable because it allows us to write tests that are self-checking: the test itself defines what the correct result should be

Sunit之所以有价值在于允许编写自检查(self-checking)的测试:测试本身定义了什么是正确的软件产出。

 

5. Think of tests as an investment for the future: having a suite of tests will be quite useful now, but it will be extremely useful when your application, or the environment in which it executes, changes in the future.

将测试看作是对未来的一项重要投资:测试套件(a suite of tests)非常有用,特别是当你的应用或者执行环境在未来有所改变的时候。

 

6. Tests play several roles. First, they provide documentation of the functionality that they cover. Moreover, the documentation is active: watching the tests pass tells you that the documentation is up-to-date. Second, tests
help developers to confirm that some changes that they have just made to a package have not broken anything else in the system—and to find the parts that break when that confidence turns out to be misplaced. Finally,
writing tests at the same time as—or even before—programming forces you to think about the functionality that you want to design, and how it should appear to the client, rather than about how to implement it. 

测试扮演了几个重要的角色。

其一,提供了其覆盖的函数的文档。值得一提的是文档是动态的:当测试通过,也就了解文档是实时的。

其二,测试帮助开发者确认某些包中的变化不会影响到系统的其他部分。

其三,编写测试在编码的同时或者之前强制你思考你所需要设计的函数以及函数应该如何展现给客户,而不是如何去实现函数。

 

7.By writing the tests first—before the code—you are compelled to state the context in which your functionality will run, the way it will interact with the client code, and the expected results.

在编码之前先写测试强制你声明函数运行的环境,以及与客户代码交换的方式, 以及期望的结果。

 

 

8 . Properties that tests should have to get a maximum benefit:
8.1. Tests should be repeatable. You should be able to run a test as often as you want, and always get the same answer.
8.2. Tests should run without human intervention. You should even be able to run them during the night.
8.3. Tests should tell a story. Each test should cover one aspect of a piece of code. A test should act as a scenario that you or someone else can read to understand a piece of functionality.
8.4. Tests should have a change frequency lower than that of the functionality they cover: you do not want to have to change all your tests every time you modify your application.

测试应当具有以下属性以使得测试的效益最大化:

1.测试应当是可以重复的。

2.测试的运行应当没有与人的交互。

3.测试应当可以讲述故事。每次测试应当覆盖一偏代码(覆盖该部分代码功能逻辑);测试应当扮演剧本的角色,你或者任何其他人从中可以读懂功能片段

4.测试的变化频度应低于其所覆盖的函数的变化频度。你不可能希望每次应用变化调整时所有的测试也做相应的改动。

 

9.eXtreme Programming advocates writing tests before writing code. This may seem to go against our deep instincts as software developers. All we can say is: go ahead and try it. We have found that writing the tests before the code helps us to know what we
want to code, helps us know when we are done, and helps us conceptualize the  functionality of a class and to design its interface. Moreover, test-first development gives us the courage to go fast, because we are not afraid that we will forget something important.

 

极限编程提倡在编写代码前先编写测试。看上去与软件开发人员的直觉冲动是相反的(译注:咱们程序员一上手拿到项目都是劈头盖脸的想怎么搭建框架满足应用进而编写实现代码,不是么?)。我们可以说的只是:大胆的去用测试驱动开发吧。我们发现在编码前先写下测试帮助我们了解什么是我们需要的编码,给我们设立了最终完成的那个里程碑(译注:可以避免过度设计),帮助我们厘清未来的函数和类的原型以及设计接口。
测试优先的开发给了我们一种勇气:敢于完成的更加快。(译注: 这在激烈竞争的商业社会中意为着什么?)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

抱歉!评论已关闭.