我的验收测试示例应该有多具体?

How specific should my acceptance test example be?

我是 Gherkin / ATDD / BDD 的新手。我正在起草以下验收测试:

Given a user is waiting for an operation to complete
    And the operation is <percent>% complete
When <threshold> seconds elapse
Then a progress indicator should be displayed
    And the progress indicator should display "<percent>%"

具体 是否足够,或者我应该修改 Given 子句以表示更具体的示例(以 SBE 术语思考),例如通过引用特定角色而不是仅 "user" 或引用正在进行的确切 "operation"(例如:获取客户列表)?

谢谢, 托尼

是的,你应该更具体一些。如果您只有一种类型的用户,或者如果此测试用例适用于每个用户组,"user" 可能足以满足您的测试需求。但是,我认为您应该指定必须等待的操作,因为 TDD 就是对您的代码感到安全,如果您没有对可能导致的所有操作进行测试,您怎么能确定它在任何地方都能正常工作延迟?

BDD

行为驱动开发是关于开发团队和业务之间的对话。其中的特性文件和场景应该始终与特定的业务需求、特性或能力相关,这意味着业务和开发团队都完全清楚它们所概述的内容。

举个例子:

Feature: Rewards for frequent flyers
   As a frequent flyer
   I should receive points to my account
   So that I am more likely to book with BDD Airlines again in the future

 Scenario: I get flyer miles
   Given I book a flight 
    And this flight earns 100 miles
   When I land
   Then my account should have 100 miles added to it

问题是,这是否概述了整个问题,还是需要更多信息? 开发团队是否能够使用此对话构建一些东西(正如你在谈论 SBE)?

这样会更好吗?:

Feature: Rewards for frequent flyers
   As a frequent flyer
   I should receive points to my account
   So that I am more likely to book with BDD Airlines again in the future

 Scenario: Passenger gets flyer miles
   Given the account number 12341234 has a ticket for the "LGW-MAN" flight
     And this route earns 100 miles
     And the ticket is scanned at "LGW"
   When the flight lands at "MAN"
   Then the account 12341234 is rewarded 100 miles

 Scenario: Passenger missed their flight
   Given the account number 12341234 has a ticket for the "LGW-MAN" flight
     And this route earns 100 miles
     And the ticket is not scanned at "LGW"
   When the flight lands at "MAN"
   Then the account 12341234 is not rewarded any miles

 Scenario: Passenger gets kicked off the plane
   Given the account number 12341234 has a ticket for the "LGW-MAN" flight
     And this route earns 100 miles
     And the ticket is scanned at "LGW"
     But the ticket is removed from the flight
   When the flight lands at "MAN"
   Then the account 12341234 is not rewarded any miles

一切都与清晰度有关,通常更多的是关于如何描述与业务相关的系统行为。

你的例子

我个人不会为了测试进度条而写一个Scenario,因为业务不应该对所使用的任何组件的实现感兴趣(他们不关心加载条,他们只是注意信息是否实际加载)。

我认为这作为单元测试会更好。

进度条是美学的。

检验美学的唯一真正方法是向人们展示它,看看他们的想法。 A/B 测试对此非常有用。 BDD 并不是特别适合美学,因为美学并不是真正关于系统的预期行为,而是关于 用户.

的预期行为

我们仍在学习如何有效地对人进行编程。在那之前,用人类而不是脚本来测试美学。

如果有某种算法适用于进度条行为的某个方面,那么当然,那将值得测试......但正如其他人所说,这是最好留给 class 级别的东西BDD,示例更直接地与代码联系在一起。

在那个级别,您可以只输入 "Given, When, Then" statements in comments 就足够了。 Class 级步骤的重用方式与系统级步骤不同,因此将它们变成可重用的抽象并不像使它们易于更改那么重要。坚持 J/N/WhateverUnit 并嘲笑其余部分。