我将 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,所以这不像是我在手动处理自己的数据持久层。一旦我将一个属性添加到我的映射文件中,它就很有可能不会被误删除。考虑到这一点,“一次性”的手动测试还不够吗?我很想听听您在这件事上的建议和经验。
最佳答案
我一般会有类似“成功创建...”这样的场景来测试成功案例(你把所有必填字段都填上,所有输入都有效,你确认,最后真的保存下来了)。 我不认为您可以轻松地为一个字段定义单独的场景,因为通常成功创建的场景需要“同时”满足其他几个条件(例如,必须填写所有必填字段)。
例如:
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 |
当然,您必须定义或扩展与新字段相关的更多场景(例如验证等)。
我认为如果采用这种方法,您可以避免出现很多“微不足道”的场景。我可以争辩说,这是“创建客户功能”的成功案例,至少值得进行一次测试。
关于testing - 进行自动验收测试以测试字段是否保存到数据库是否重要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6279097/