我从Techtalk上了解到,将步骤定义与功能耦合是一种反模式。但是,我想知道如何组织步骤定义,以便在代码中轻松看到哪些步骤组合在一起。
例如,我应该为每个功能创建一个代码文件,为共享的步骤创建一个单独的文件吗?还是应该有一套功能的代码文件?
我倾向于以几种方式来组织步骤定义,具体取决于步骤定义文件的大小。
分开的数据和UI步骤
我有很多Given some thing exists in the database步骤,因此通常将它们放入一个名为DataSteps.cs的文件中。我也有很多Then something exists in the database步骤,这些都进入了DataAssertionSteps.cs。
我所有的When I fill in some form field步骤都在FormSteps.cs中进行。每当我需要Then something in the form is enabled|disabled或断言表单字段具有某个值时,我都会将其扔到FormPresentationSteps.cs中。
按模型分开的步骤
有时,我的步骤定义文件会变得很大,因此我开始将步骤定义移动到与某个模型相关的文件中。说我有一个Person模特。我可能会创建一个PersonSteps.cs文件,该文件分为三个区域:
[Binding]
public class PersonSteps
{
#region Given
// Given a person exists with the following attributes:
#endregion
#region When
// When something something about a Person
#endregion
#region Then
// Then a person should exist with the following attributes:
#endregion
}
Run Code Online (Sandbox Code Playgroud)
基本上,我从以下文件开始:
Given用于设置测试数据的Then用于断言数据库中正确存在数据的s| 归档时间: |
|
| 查看次数: |
1396 次 |
| 最近记录: |