|
Post by account_disabled on Jan 29, 2024 5:07:23 GMT
到目前为止,每个人都听说过测试驱动开发(TDD),以及它对您的产品和开发生命周期带来的好处。这确实是理所当然的。每次你为一段代码编写测试时,你就知道代码是有效的。而且,更重要的是,您将来会知道该代码是否损坏。 行为驱动开发 (BDD) 是此概念的扩展,但您不是在测试您的代码,而是在测试您的产品,特别是您的产品是否按照您的期望运行。 在本文中,我将向您展示如何启动并运行 Cucumber,这是一个运行以 BDD 风格编写的自动化验收测试的框架。这些测试的优点是它们可以用简单的英语编写,因此可以被项目中的非技术人员理解。阅读后,您将能够确定 Cucumber 是否适合您和您的团队,并开始编写您自己的验收测试。 准备好?然后让我们深入了解一下。 BDD 与 TDD — 那么,有什么区别? Learn to Code with JavaScript 主要是测试的构建和编写方式。 在 TDD 设置中,测试由编写正在测试的代码的开发人员编写、维护和理解。 很可能根本没有其他人需要阅读测试,这很好。 在 BDD 设置中,测试需要被更多人理解,而不仅仅是编写功能的开发人员。还有更多的利益相关者对产品的行为感兴趣。 这些人员可能包括质量检查人员、产品分析师、销售人员,甚至高层管理人员。 这意味着,在理想的情况下,BDD 测试的编写方式需要让任何了解产品 WhatsApp 号码数据 的人都能够接受测试并理解它们。 这是以下之间的区别: 这两个测试的作用完全相同,但一个实际上是人类可读的,另一个只能由同时了解 JavaScript 和 Selenium 的人可读。 本文将向您展示如何使用 Cucumber.js 框架在 JavaScript 项目中实现 BDD 测试,从而使您能够从产品的这一级别测试中受益。 Learn to Code with JavaScript 什么是黄瓜/小黄瓜? Cucumber 是行为驱动开发的测试框架。它的工作原理是允许您以Gherkin形式定义测试,并通过将这些 Gherkin 绑定到代码来使它们可执行。 Gherkin 是用于编写 Cucumber 测试的领域特定语言 (DSL)。 它允许以人类可读的格式编写测试脚本,然后可以在产品开发的所有利益相关者之间共享。 Gherkin 文件是包含用 Gherkin 语言编写的测试的文件。这些文件通常具有.feature文件扩展名。这些小黄瓜文件的内容通常简称为“小黄瓜”。 小黄瓜 在 Gherkin 定义的测试中,您拥有功能和场景的概念。这些类似于其他测试框架中的测试套件和测试用例,允许以干净的方式构建测试。 场景实际上只是一个测试。它应该测试您的应用程序中的一件事。 功能是一组相关的场景。因此,它将测试您的应用程序中的许多相关内容。理想情况下,Gherkin 文件中的功能将紧密映射到应用程序中的功能 - 因此得名。 每个 Gherkin 文件仅包含一个功能,并且每个功能都包含一个或多个场景。 场景由步骤组成,这些步骤以特定方式排序: Learn to Code with JavaScript 给定 – 这些步骤用于在进行测试之前设置初始状态 When – 这些步骤是要执行的实际测试 然后 – 这些步骤用于断言测试结果 理想情况下,每个场景都应该是一个测试用例,因此 When 步骤的数量应该保持非常少。
|
|