给定自动电子邮件通知的时间场景
Given When then scenario for automatic email notification
对于必须在特定状态更改后 1 个工作日发送通知的电子邮件通知场景,您将如何编写 Given when then 构造?
这样看起来对吗?
Given that I'm the system
and the user of a particular type T
and the state is S
When it is 1 business day after the date state was changed to x
then send an email notification with xxx content.
我有疑问的原因是我的理解是给定部分我们的先决条件在这种情况下是 A. 特定类型的用户 B. 状态是 S 和 C. 它是日期后 1 天状态改变了。
如果所有这些先决条件都在 Given 部分,那么什么会在 when 部分?我的理解是 'when' 部分用于事件触发器。除了 运行 通知作业外,没有其他操作。那么这是正确的吗?
Given the user of a particular type T
and the state is S
and it is 1 business day after the date state was changed to x
When the email notification process triggered
then send an email notification to all users of type T with xxx content.
我很感激你的想法
你走对了!
所以正如你之前所说的 When
是一个触发器,所以让我们更深入地研究一下。
Gherkin 用于行为驱动开发 (BDD),因为您正在尝试模拟行为。
给定 - 输入 - 先决条件
这些是在动作或触发发生之前需要预期的事情。他们为将要发生的动作设置测试。
何时 - 触发 - 动作
这些是触发结果的用户行为。这是BDD
中的B
然后-输出-结果
这是最终结果,当行为完成时用户应该期待什么。
你的立场
所以你处在一个有趣的情况下,因为正如你所指出的,没有任何行为。所以这是棘手的部分,虽然使用 Given-When-Then 格式很好,但在没有可靠的用户行为的情况下,使用 Given-Then 或 When-Then 格式也是完全有效的。所以在那种情况下:
Given it is 1 business day after the date state was changed to x
和
When it is 1 business day after the date state was changed to x
两者同样有效。
关于您的第二个代码块,您需要问自己的问题是 the email notification process triggered
触发器还是结果?我个人认为这是输入的结果。如果您确实认为需要它,那么我认为您应该像这样编写测试:
Given there is a user of type T
And the state is S
And it is 1 business day after the date state was changed to x
Then the email notification process should have triggered
And send an email notification to all users of type T with xxx content.
奖金 -- 如何措辞你的测试并避免实现语言
不是你问的,但实际上有一种方法可以改进你的测试措辞。您希望将测试与实际实现分离。这意味着避免使用“发送”、“单击”或“键入”等词,而专注于行为和结果。参加你的考试我会这样改写它:
Given there is a user of type T
And the state is S
And it is 1 business day after the date state was changed to x
Then all users of type T should be notified of xxx
我删除了电子邮件通知步骤,因为这可以从最后一步推断出来。我还将最后一步与实现语言分离。这里重要的不是向用户发送电子邮件,而是向他们通知内容。我认为您的 Given
步骤也应该根据您的业务逻辑进行更改,因为它们目前与您的实施非常相关。
对于必须在特定状态更改后 1 个工作日发送通知的电子邮件通知场景,您将如何编写 Given when then 构造?
这样看起来对吗?
Given that I'm the system
and the user of a particular type T
and the state is S
When it is 1 business day after the date state was changed to x
then send an email notification with xxx content.
我有疑问的原因是我的理解是给定部分我们的先决条件在这种情况下是 A. 特定类型的用户 B. 状态是 S 和 C. 它是日期后 1 天状态改变了。
如果所有这些先决条件都在 Given 部分,那么什么会在 when 部分?我的理解是 'when' 部分用于事件触发器。除了 运行 通知作业外,没有其他操作。那么这是正确的吗?
Given the user of a particular type T
and the state is S
and it is 1 business day after the date state was changed to x
When the email notification process triggered
then send an email notification to all users of type T with xxx content.
我很感激你的想法
你走对了!
所以正如你之前所说的 When
是一个触发器,所以让我们更深入地研究一下。
Gherkin 用于行为驱动开发 (BDD),因为您正在尝试模拟行为。
给定 - 输入 - 先决条件
这些是在动作或触发发生之前需要预期的事情。他们为将要发生的动作设置测试。
何时 - 触发 - 动作
这些是触发结果的用户行为。这是BDD
中的B然后-输出-结果
这是最终结果,当行为完成时用户应该期待什么。
你的立场
所以你处在一个有趣的情况下,因为正如你所指出的,没有任何行为。所以这是棘手的部分,虽然使用 Given-When-Then 格式很好,但在没有可靠的用户行为的情况下,使用 Given-Then 或 When-Then 格式也是完全有效的。所以在那种情况下:
Given it is 1 business day after the date state was changed to x
和
When it is 1 business day after the date state was changed to x
两者同样有效。
关于您的第二个代码块,您需要问自己的问题是 the email notification process triggered
触发器还是结果?我个人认为这是输入的结果。如果您确实认为需要它,那么我认为您应该像这样编写测试:
Given there is a user of type T
And the state is S
And it is 1 business day after the date state was changed to x
Then the email notification process should have triggered
And send an email notification to all users of type T with xxx content.
奖金 -- 如何措辞你的测试并避免实现语言
不是你问的,但实际上有一种方法可以改进你的测试措辞。您希望将测试与实际实现分离。这意味着避免使用“发送”、“单击”或“键入”等词,而专注于行为和结果。参加你的考试我会这样改写它:
Given there is a user of type T
And the state is S
And it is 1 business day after the date state was changed to x
Then all users of type T should be notified of xxx
我删除了电子邮件通知步骤,因为这可以从最后一步推断出来。我还将最后一步与实现语言分离。这里重要的不是向用户发送电子邮件,而是向他们通知内容。我认为您的 Given
步骤也应该根据您的业务逻辑进行更改,因为它们目前与您的实施非常相关。