如何检查黄瓜没有变化?

| 我要用黄瓜/小黄瓜测试的业务场景(实际上是specflow)是给定Web表单上的一组输入,我发出请求,并且需要确保(在某些条件下)结果返回时,特定字段未更改(在其他情况下,它会更改)。例如。 鉴于我在数据输入屏幕上 当我选择“不更新frobnicator”时 然后我提交表格 并显示结果 然后,frobnicator不会更新 我将如何编写“未更新frobnicator”步骤? 一种选择是在“我提交表单”之前运行一个步骤,该步骤的内容类似于“我记得frobnicator的值”,但是那有点垃圾-这是一个可怕的泄漏。实施细节。它分散了测试的注意力,而不是企业如何描述这一点。实际上,我必须在任何人看到的时候解释这种说法。 是否有人对如何更好地实现这一点有任何想法,理想情况下是书面形式?     
已邀请:
        我不同意先前的答案。 您觉得自己想写的小黄瓜文字可能是正确的。 我将对其进行少许修改以使其成为“ 0”步骤,这是正在测试的特定操作。
Given I am on the data entry screen
And I have selected \"do not update frobnicator\"
When I submit the form
Then the frobnicator is not updated
断言的确切程度取决于程序如何更新frobnicator,以及为您提供什么选项。.但是为了显示可能,我假设您已将数据访问层与UI分离并且能够模拟它-因此监视更新。 我使用的模拟语法来自Moq。 ...
private DataEntryScreen _testee;

[Given(@\"I am on the data entry screen\")] 
public void SetUpDataEntryScreen()
{
    var dataService = new Mock<IDataAccessLayer>();
    var frobby = new Mock<IFrobnicator>();

    dataService.Setup(x => x.SaveRecord(It.IsAny<IFrobnicator>())).Verifiable(); 
    ScenarioContext.Current.Set(dataService, \"mockDataService\");

    _testee = new DataEntryScreen(dataService.Object, frobby.Object);
}
这里要注意的重要一点是,给定的步骤将我们正在测试的对象与它所需要的所有东西一起设置...我们不需要一个笨拙的步骤就可以说“”,并且我有一个frobnicator,我\ “要记忆”,这对利益相关者不利,对您的代码灵活性也不利。
[Given(@\"I have selected \"\"do not update frobnicator\"\"\")]
public void FrobnicatorUpdateIsSwitchedOff()
{
    _testee.Settings.FrobnicatorUpdate = false;
}

[When(@\"I submit the form\")]
public void Submit()
{
    _testee.Submit();
}

[Then(@\"the frobnicator is not updated\")]
public void CheckFrobnicatorUpdates()
{
    var dataService = ScenarioContext.Current.Get<Mock<IDataAccessLayer>>(\"mockDataService\");

    dataService.Verify(x => x.SaveRecord(It.IsAny<IFrobnicator>()), Times.Never);
}
根据您的情况调整安排,行动,断言的原则。     
        考虑一下如何手动测试它:
Given I am on the data entry screen
And the blah is set to \"foo\"
When I set the blah to \"bar\"
And I select \"do not update frobnicator\"
And I submit the form
Then the blah should be \"foo\"
    

要回复问题请先登录注册