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

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?

主站蜘蛛池模板: 伽师县| 临洮县| 炎陵县| 漳浦县| 农安县| 略阳县| 景德镇市| 斗六市| 天长市| 麦盖提县| 崇文区| 梁山县| 三原县| 双城市| 嘉鱼县| 磴口县| 夏邑县| 汉阴县| 龙山县| 门头沟区| 鄂伦春自治旗| 翁源县| 泸州市| 绥阳县| 广河县| 邯郸市| 怀宁县| 合肥市| 奉新县| 磐石市| 手游| 千阳县| 外汇| 安化县| 鸡东县| 兴仁县| 焦作市| 金华市| 石景山区| 玉溪市| 高青县|