Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cucumber 如何检查黄瓜没有任何变化?_Cucumber_Bdd_Specflow_Gherkin - Fatal编程技术网

Cucumber 如何检查黄瓜没有任何变化?

Cucumber 如何检查黄瓜没有任何变化?,cucumber,bdd,specflow,gherkin,Cucumber,Bdd,Specflow,Gherkin,我试图用cucumber/gherkin(实际上是specflow)测试的业务场景是,给定web表单上的一组输入,我发出请求,并且需要确保(在某些条件下),当返回结果时,某个特定字段没有改变(在其他条件下,确实如此)。例如 假设我在数据输入屏幕上 当我选择“不更新蛙鸣器”时 我提交表格 并显示结果 则不会更新蛙鸣器 我将如何编写“蛙鸣器未更新”步骤 一种选择是在“我提交表单”之前运行一个步骤,该步骤的内容类似于“我记得frobnicator的值”,但这有点垃圾——这是一个可怕的实现细节泄漏。这会

我试图用cucumber/gherkin(实际上是specflow)测试的业务场景是,给定web表单上的一组输入,我发出请求,并且需要确保(在某些条件下),当返回结果时,某个特定字段没有改变(在其他条件下,确实如此)。例如

假设我在数据输入屏幕上 当我选择“不更新蛙鸣器”时 我提交表格 并显示结果 则不会更新蛙鸣器

我将如何编写“蛙鸣器未更新”步骤

一种选择是在“我提交表单”之前运行一个步骤,该步骤的内容类似于“我记得frobnicator的值”,但这有点垃圾——这是一个可怕的实现细节泄漏。这会分散测试的注意力,而不是业务部门如何描述这一点。事实上,每当有人看到这句话,我都要解释


是否有人对如何更好地实现这一点有任何想法,理想情况下是书面的?

想想如何手动测试它:

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"

我不同意前面的答案。 你觉得你想写的小黄瓜文本可能是对的。 我将对它进行一点修改,以使
When
步骤是正在测试的特定操作

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
您如何准确地断言结果将取决于您的程序如何更新Frobnitator,以及它为您提供了哪些选项。。但为了证明这是可能的,我假设您已经将数据访问层与UI解耦,并且能够模拟它,从而监视更新

我使用的模拟语法来自Moq

privatedataentryscreen\u测试对象;
[给定(@“我在数据输入屏幕上”)]
public void SetUpDataEntryScreen()
{
var dataService=new Mock();
var frobby=new Mock();
dataService.Setup(x=>x.SaveRecord(It.IsAny()).Verifiable();
ScenarioContext.Current.Set(dataService,“mockDataService”);
_testee=newdataentryscreen(dataService.Object,frobby.Object);
}
这里需要注意的重要一点是,给定的步骤设置了我们正在测试的对象,并提供了它所需要的所有东西。。。我们不需要一个单独的笨拙步骤来说“我有一个我将要记住的蛙鸣器”——这对涉众和代码灵活性都是有害的

[给定(@“我已选择”“不更新蛙鸣器”“)]
public void frobNicatorUpdatesSwitchedOff()
{
_testee.Settings.FrobnicatorUpdate=false;
}
[当(@“我提交表格”)]
公开作废提交()
{
_受试者提交();
}
[然后(@“蛙鸣器未更新”)]
public void CheckFrobnicatorUpdates()
{
var-dataService=ScenarioContext.Current.Get(“mockDataService”);
验证(x=>x.SaveRecord(It.IsAny()),Times.Never);
}
根据你的情况调整安排、行动、主张的原则

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);
}
[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);
}