我从Techtalk了解到,对特征的耦合步骤定义是一种反模式。 但是我想知道如何组织我的步骤定义,以便我可以在代码中轻松地看到哪些步骤在一起。
例如,我应该为每个功能创建一个代码文件,为共享的步骤创建一个单独的文件吗?或者我应该有一组功能的代码文件吗?
答案 0 :(得分:4)
我倾向于以几种方式组织步骤定义,具体取决于步骤定义文件的大小。
单独的数据和用户界面步骤
我有很多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
}
基本上我从这些文件开始:
Given
Then