我正在使用Specflow(http://specflow.org/)编写一些集成测试,我想运行一个Scenario.有没有办法用Resharper 6运行单个场景?顺便说一句,我配置specflow来使用MSTest.
我的Specflow测试看起来像:
Feature: Customer management
Scenario: Add a new Customer into system
Given the User has entered the customer with the following data
| name | last_name | birthday |
| Peter | Stein | 12.09.1955 |
When the User has pressed the Save Button
Then the following customer should be stored in the data base
| name | last_name | birthday |
| Peter | Steim | 12.09.1955 |
Scenario: Second scenario.....
Scenario: Third scenario.....
Run Code Online (Sandbox Code Playgroud)
我想只运行第一个场景.
我们试图通过以下方法来打破测试,以防DoAyncStuff()方法中发生故障:
[Given(@"There is something")]
public async Task GivenSomething()
{
await DoStuff();
}
private async Task DoStuff()
{
await Task.Run(() => Thread.Sleep(1000));
throw new ApplicationException("Boom");
}
Run Code Online (Sandbox Code Playgroud)
但它实际上是一个快乐的绿色运行,直到你使用.Wait()或.Result:
[Given(@"There is something")]
public void GivenSomething()
{
DoStuff().Wait();
}
Run Code Online (Sandbox Code Playgroud)
问题似乎出现在NUnit generated-spec中,如下所示:
public virtual void SomethingAsync()
{
...
testRunner.Given("There is something", ...);
...
}
Run Code Online (Sandbox Code Playgroud)
这似乎与以下代码一起使用:
public virtual async Task SomethingAsync()
{
...
await this.ScenarioSetup(scenarioInfo);
...
}
Run Code Online (Sandbox Code Playgroud)
上面的代码是手动编辑的自动生成的文件,所以我实际上正在寻找一种自动生成以下代码的方法.
该文档似乎是asyncronous API唯一可用的选项,但实际上它适用于Silverlight,据我所知使用某种API,而我们更喜欢使用本机C#await关键字.
是否有一种方法可以原生处理async/awaitSpecFlow步骤?
我在Visual Studio 2010 Pro中使用了Specflow,但是想在我的个人项目中使用它.不幸的是我只有VS210 Express.
我还没有设法让Specflow在VS2010 Express中运行.有没有人这样做过或者甚至是可能的.
谢谢,
我有两个类(A类和B类)都标有[Binding].目前我正在使用每个功能的类.类A和B都有一个如下所示的步骤:
[Given(@"an employee (.*) (.*) is a (.*) at (.*)")]
public void GivenAnEmployeeIsAAt(string firstName, string lastName, string role, string businessUnitName)
Run Code Online (Sandbox Code Playgroud)
当我运行A类中定义的功能的场景,并且测试运行器执行上面指出的步骤时,将执行B类中的匹配步骤.
"步骤"也是全球性的吗?我认为只有"钩子"方法是全局的,即BeforeScenario,AfterScenario.我不希望这种行为为"给定","然后"和"何时".有没有什么办法解决这一问题?我尝试将这两个类放在不同的命名空间中,这也不起作用.
另外,如果我把它们放在不同的类中,我希望每个"Given"是独立的,我可能会滥用SpecFlow吗?
目前我们有这个步骤:
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceForProductPToN(string product, string priceStr)
Run Code Online (Sandbox Code Playgroud)
我想补充一步:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
Run Code Online (Sandbox Code Playgroud)
然而,规范流程给出了两个步骤之间的"步骤中找到的模糊步骤定义"错误.
我累了:
[When(@"I set the scenario price for product (.*) to (.*) in the (.*) zone")]
[When(@"I set the scenario price for product (.*) to (.*)")]
public void WhenISetTheScenarioPriceInZoneForProductPToN(string product, string priceStr, string zone)
Run Code Online (Sandbox Code Playgroud)
但失败的是"绑定错误:参数计数不匹配!" 我希望它会在第二次"当"时传递null.
我正在尝试设置SpecFlow进行集成/验收测试.我们的产品在Sqlite中有一个支持数据库(虽然不是很大).
事实证明这实际上是一个有点棘手的问题; 如何为测试建模数据库?
我想知道其他人使用什么模式进行与后备数据库的集成/验收测试.
我可以想到以下方法:
我有这个功能文件:
Scenario Outline: Example
Given I am a user
When I enter <x> as an amount
Then the result should be <result>
Examples:
| x | result |
| 3 | 3 |
| 1 | 1 |
Run Code Online (Sandbox Code Playgroud)
我的问题是,在运行之后,每个示例都标记为 variant #
有没有办法说明每个示例行实际测试的内容,以便在报告中我们更好地了解测试的内容,而不仅仅是:
Scenario: Example, Variant 0
Scenario: Example, Variant 1
Scenario: Example, Variant 2
Run Code Online (Sandbox Code Playgroud)
我正在努力帮助我们的测试人员获得更有意义的报告; 通常有一个原因是他们编写了多个示例,并且他们希望以某种方式显示该示例的原因.
我正在尝试创建一组新的测试来测试我正在处理的遗留网站.该站点在后端使用数据库.我打算使用SpecFlow和Selenium,但是我对处理清理数据的最佳方法感到有点困惑.
目前,我有一组数据库备份,其中包含一组样本数据,我会在每次测试运行之前将其恢复.然而,这很麻烦,因此我只想在发布之前对关键测试运行执行此操作,并使持续集成运行在两者之间的同一数据库上运行.
目前我有大量的测试,如下所示:
Secenario: Test Item Creation
Given I am logged in
When I create an item with a unique name
Then an item exists with the unique name
Run Code Online (Sandbox Code Playgroud)
when步骤使用GUID来确保名称是唯一的,然后步骤可以通过模块变量访问它以检查它是否存在.
就像我说的那样,我有很多类似的测试,我在同一个数据库上多次运行它们,所以测试系统充满了物品,这会减慢搜索速度等.
我的问题是处理这个问题的最佳方法是什么?我应该在测试中创建另一个步骤,再次删除该项目,如下所示:
Secenario: Test Item Creation
Given I am logged in
When I create an item with a unique name
Then an item exists with the unique name
Then delete the item with the unique name
Run Code Online (Sandbox Code Playgroud)
或者我的测试框架应该以某种方式处理这个问题?如果是这样,人们做什么?鉴于SpecFlow步骤的全局性,我认为如果具有父子关系的多个项目可能成为问题,则以正确的顺序获取拆除步骤.
我按照入门说明操作,上下文菜单中缺少"生成步骤定义".
我尝试从nuget为mstest添加额外的specflow包,但仍然没有.
我是Specflow和BDD的忠实粉丝.在各种项目中,它对我来说非常棒.
我还没有解决的一个挑战是以某种方式组织我的特征文件和场景,这使得它易于导航和探索.想象一年后,其他人想要来参加并了解该系统.从哪儿开始?什么是最重要的,什么不重要?功能之间有什么关系?系统是否处理特定方案?作者有没有想过这个问题?
任何人都可以分享一些专注于此的技巧,阅读或工具吗?