2

我将 SpecFlow 用于自动化验收测试框架,将 NHibernate 用于持久性。我正在处理的 Intranet 应用程序的许多 UI 页面都是基本的数据输入页面。显然,将字段添加到这些页面之一被认为是“功能”,但我想不出除此之外的任何场景

Given that I enter data X for field Y on Record 1 
And I click Save 
When I edit Record 1 
Then I should data X for field Y

像这样自动化测试有多普遍和必要?此外,我正在使用 NHibernate,所以它不像我正在处理我自己的数据持久层。一旦我将一个属性添加到我的映射文件中,它很有可能不会被错误地删除。考虑到这一点,“一次性”手动测试还不够吗?我很想听听您在这件事上的建议和经验。

4

1 回答 1

2

我通常有诸如“成功创建...”之类的场景来测试成功案例(您填写所有必填字段,所有输入均有效,您确认,最后真正保存)。我不认为您可以轻松地为单个字段定义单独的场景,因为通常成功创建的场景需要“同时”满足几个其他条件(例如,必须填写所有必填字段)。

例如:

Scenario: Successful creation of a customer
Given I am on the customer creation page
When I enter the following customer details
| Name | Address |
| Cust | My addr |
And I save the customer details
Then I have a new customer saved with the following details
| Name | Address |
| Cust | My addr |

稍后我可以在这个场景中添加额外的字段(例如账单地址):

Scenario: Successful creation of a customer
Given I am on the customer creation page
When I enter the following customer details
| Name | Address | Billing address |
| Cust | My addr | Bill me here    |
And I save the customer details
Then I have a new customer saved with the following details
| Name | Address | Billing address |
| Cust | My addr | Bill me here    |

当然,您必须定义或扩展与新字段相关的更多场景(例如验证等)。

I think if you take this approach you can avoid having a lot of "trivial" scenarios. And I can argue that this is the success case of the "create customer feature", which deserves a single test at least.

于 2011-06-15T11:28:01.917 回答