官术网_书友最值得收藏!

Test-driven development

It seems to make sense to write your code first and then to test it, as we did in our AddressValidator example above. Many people follow this approach. However, many others follow a process called TDD, where the tests are written first. Why do this? Let's take a brief aside before answering the question.

If you look at RSpec's official documentation, you will find that instead of the word test, the word example is used to describe the inpidual assertions to be found within the it block. Although it may appear less natural than test, in some ways example is more accurate. Automated tests rarely provide conclusive proof that a software system, or even just one of its functions, works. Most often, they contain a few test cases, which are nothing but examples of the code in action. Moreover, one of the main benefits of an automated assertion is to document the way the code behaves. Whereas test suggests a proof of correctness, example just suggests an instance of the code in action.

Coming back to the question of why someone would write their test before their code, we can apply the concept of the example. A methodical software engineer could benefit from documenting the code about to be written with some examples. Rather than adding these as comments in the code, the documentation can be written in the form of automated tests, or assertions. This way, as the code is being written, the tests can be run to give some feedback about how close, or how far, the code is to performing as initially expected.

If we refer to RSpec's home page, there is a link provided (https://relishapp.com/rspec), where we can read the following description:

RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

We see that TDD is mentioned, but the first sentence identifies RSpec with BDD. Although a definition is given, it refers to three other methodologies, leaving us perhaps with only a vague impression of some fancy approach to software development. So what is BDD really?

主站蜘蛛池模板: 临西县| 道真| 克什克腾旗| 滨州市| 龙井市| 神木县| 建湖县| 威信县| 百色市| 鹤庆县| 新蔡县| 云阳县| 新河县| 广平县| 梁河县| 招远市| 曲阳县| 运城市| 云南省| 玉树县| 孟津县| 筠连县| 高淳县| 大同县| 华蓥市| 山东省| 元朗区| 乌拉特中旗| 无锡市| 营口市| 上虞市| 卢氏县| 彰武县| 天台县| 郯城县| 阜城县| 资阳市| 黄浦区| 秭归县| 岱山县| 印江|