我已经将Specflow配置为定位MsTest框架(而不是NUnit),方法是在我的'specs'类库的app.config中指定它:
<configSections>
<section name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest.2010" />
</specFlow>
Run Code Online (Sandbox Code Playgroud)
所以一旦它到位,我可以看到我的测试夹具是由Specflow自定义工具正确生成的,具有正确的TestClassAttribute()和方法等:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
...
Run Code Online (Sandbox Code Playgroud)
specs类构建,但现在我无法使用我的vista 64盒上的Visual Studio 2010中的Test - > Run - > All Tests in Solution运行测试.为什么VS不认为这些是有效的测试运行?
我正在使用ASP.NET MVC 3构建REST API.我正在使用SpecFlow和NUnit作为测试运行器来实现BDD风格.
由于它是一个REST API,因此测试Url:s显然非常重要,因此我希望能够在规范中进行真正的HTTP调用.
我现在正在寻找有关如何实现Cross Process Mocking的技巧.简而言之,我想用我在Specs中生成的实体来模拟数据层.
在Rails应用程序中,我会使用Webrat.有没有相当于.NET的东西呢?
我已经尝试过Deleporter,但它似乎无法"发送"高级构造(在规范中创建一个简单的字符串并在Deleporter中使用它,但不适用于自定义类,属性都变为null)
有没有人有关于如何做到这一点的经验或提示?
编辑:我在Deleporter尝试做的事情是这样的(我知道我可以在Deleporter代码中生成模型,但这是一个简化的例子,所以这对我不起作用):
var models = Builder<Foo>.CreateListOfSize(300);
Deleporter.Run(() =>
{
var mockService = new Mock<IFooService>();
// Models will be a list of 300 Foos but the foos properties will all be null
mockService.Setup(s => s.GetStuff()).Returns(models);
ObjectFactory.Inject(mockService.Object);
});
Run Code Online (Sandbox Code Playgroud) 我最近在设置完全自动化的夜间构建/测试/部署环境时遇到了一些麻烦.简要解释一下设置.我们使用Mercurial作为源控制系统,使用TeamCity作为构建服务器.它目前在一台单独的机器上只有一个构建代理,以保持简单.
这个想法如下:每晚都有一个TeamCity构建运行.从Mercurial存储库中提取最新信息,运行构建,运行单元测试,部署到测试服务器,针对新部署的测试服务器运行验收测试(在构建代理上),如果所有这些通过将批次部署到临时服务器.除了验收测试之外,我已经完成了所有工作.这些都是使用SpecFlow和WatiN完成的.Everyhting在开发机器上运行良好(Windows 7 32位).但是,当我尝试运行验收测试(TeamCity中的NUnit)时,运行器报告失败,因为步骤[浏览器] .ContainsText(browserText).所有步骤都正确运行,如果我在构建代理上的同一浏览器中复制步骤(获得完全管理员访问权限),我可以看到文本存在.所以据我所知,测试应该通过.
我发现这个stackoverflow线程让我觉得我可能正在做一些关于如何保持浏览器实例的错误.解释一下:我有一套常见的步骤,例如"当我点击X按钮时"或"当我将文字X输入字段Y时"和有问题的那个"然后我显示X".因为我正在尽可能多地重复使用测试,所以我也推广了一个@requires_browser场景需求,然后定义如下:
[BeforeScenario("requires_browser")]
public void RequiresBrowserBeforeFeature()
{
Settings.MakeNewIeInstanceVisible = false;
ScenarioContext.Current.Set<Browser>(new IE(true));
}
[AfterScenario("requires_browser")]
public void RequiresBrowserAfterFeature()
{
ScenarioContext.Current.Get<Browser>().Close();
ScenarioContext.Current.Get<Browser>().Dispose();
}
Run Code Online (Sandbox Code Playgroud)
然后是共同的步骤:
[Then("I am shown \"(.*)\"")]
public void ThenIAmShown(string text)
{
Assert.IsTrue(ScenarioContext.Current.Get<Browser>().ContainsText(text));
}
Run Code Online (Sandbox Code Playgroud)
从这里我可以定义其他常见步骤,将文本输入文本框,单击按钮等.所有这一切都完美适用于开发环境,在visual studio 2010中运行[以管理员身份].
我认为ScenarioContext应该保留到测试完成之前我错了吗?
到目前为止我尝试过的:
配置构建代理程序服务以作为本地系统(SYSTEM)运行.这导致了所描述的问题 - ThenIAmShown(字符串文本)方法将始终失败.它与已启用本地桌面的交互.
配置的构建代理服务以网络管理员身份运行(完全管理员权限).此设置甚至不会运行测试.我得到的例外:
TearDown方法失败.WatiN.Core.Exceptions.BrowserNotFoundException:找不到匹配约束的IE窗口:等待附加到新创建的IE实例时超时.搜索在"30"秒后过期.TearDown:System.Collections.Generic.KeyNotFoundException:给定的键不在字典中.在WatiN.Core.IE.CreateIEPartallyInitializedInNewProcess()at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri,IDialogHandler logonDialogHandler,Boolean createInNewProcess)...
已经将Interop.SHDocVw.dll和Microsoft.mshtml.dll组件添加到bin目录(在项目引用中复制到输出).
从构建代理运行NUnit UI.这按预期运行单元测试.让我相信可能存在安全问题.Windows Server 2008 R2 Enterprise上的Runnint NUnit 2.0.5.
有谁有这个问题?
在我的功能文件中,IntelliSense表示有一个名为的关键字Scenarios.注意它是复数.我已经完成了文档,但找不到任何引用.任何人都可以解释它的用途以及如何使用它?
SpecFlow非常棒 - 它非常有助于我们进行适当的集成测试.
我想知道的一件事是,是否有办法告诉SpecFlow将其他NUnit属性添加到它在功能代码隐藏文件中创建的测试类中.
现在,我的测试类生成如下:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Some action description here")]
public partial class MySampleFeature
{
......
}
Run Code Online (Sandbox Code Playgroud)
在SpecFlow中是否有任何方法告诉它添加额外的NUnit属性来定义测试的类别 - 如下所示:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.8.1.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Some action description here")]
[NUnit.Framework.Category("LongRunningTests")] <== add this "Category" attribute
public partial class MySampleFeature
{
......
}
Run Code Online (Sandbox Code Playgroud)
手动将其添加到生成的代码隐藏是浪费 - 下次SpecFlow重新生成代码隐藏时,我必须记住再次执行它(很可能,我会忘记).
如果SpecFlow中还没有这种能力 - 如何申请加入?:-)
如何在表中传递空格?
Background:
Given the following books
|Author |(here several spaces)Title(here several spaces)|
Run Code Online (Sandbox Code Playgroud) SpecFlow相当新,所以请耐心等待.
我正和一位同事一起基本了解你可以用SpecFlow做些什么.
我们使用了经典的FizzBuzz问题,我们用它来测试单元测试,以比较我们在SpecFlow中如何处理类似问题.
我们编写了我们的场景,如下所示增长代码:
(请原谅命名只是想获得测试令状)
Scenario: 1 is 1
Given there is a FizzBuzzFactory
When you ask What I Am with the value of 1
Then the answer should be 1 on the screen
Scenario: 3 is Fizz
Given there is a FizzBuzzFactory
When you ask What I Am with the value of 3
Then the answer should be Fizz on the screen
Scenario: 5 is Buzz
Given there is a FizzBuzzFactory
When you ask What I Am with the …Run Code Online (Sandbox Code Playgroud) 有没有办法在SpecFlow功能文件中重用数据?例如,我有两个场景,它们都使用相同的数据表:
Scenario: Some scenario 1
Given I have a data table
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
When ...
Scenario: Some scenario 2
Given I have a data table
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
And I have another data table
| Field Name | Value |
| Brand | "Volvo" |
| City | "London" |
When ...
Run Code Online (Sandbox Code Playgroud)
在这些简单的例子中,表格很小并且没有大问题,但在我的情况下,表格有20多行,每个表格至少用于5次. …
我正在使用Reshaper和Specflow,ResharperCode Inspection正在标记步骤定义,绑定和挂钩,因为从未使用过.
我试着用这里的答案
但无法成功获取正确选取的外部注释.这是我在External Annotations文件中尝试的内容: -
<assembly name="TechTalk.SpecFlow.dll">
<member name="T:TechTalk.SpecFlow.BindingAttribute">
<attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
</member>
<member name="T:TechTalk.SpecFlow.GivenAttribute">
<attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
</member>
<member name="T:TechTalk.SpecFlow.WhenAttribute">
<attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
</member>
<member name="T:TechTalk.SpecFlow.ThenAttribute">
<attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
</member>
</assembly>
Run Code Online (Sandbox Code Playgroud)
我试过保存在C:\ Program Files(x86)\ JetBrains\ReSharper\v8.2\Bin和C:\ Program Files(x86)\ JetBrains\ReSharper\v8.2\Bin\ExternalAnnotations(不是因为在默认安装中不存在ExternalAnnotations文件夹,所以应该去哪里
但是当我关闭并重新打开VS时,检查仍然选择Bindings并将步骤defs视为未使用: -
Solution qdf.AcceptanceTests.sln
Project Alpari.QualityAssurance.SpecFlowExtensions
Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:7 Class 'CrossStepDefinitionFileTwo' is never used
Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:10 Method 'GivenICreateAnInstanceOfStepDefinitionOneFromStepDefinitionTwo' is never used
Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:42 Method 'GivenICallAMethodInStepDefinitionTwoThatCallsTheSameMethodInStepDefinitionFileOne' is never used
Run Code Online (Sandbox Code Playgroud)
谁能告诉我在配置这个时我做错了什么?
编辑完成xml后,亚历山大的帖子后工作正常: -
<!--Deploy to %ReSharperInstallDir%\Bin\ExternalAnnotations
to check the ExternalAnnotations have worked, highlight …Run Code Online (Sandbox Code Playgroud) 我以前见过这个问题,但我认为它没有得到解决.基本上我的设置是这样的:VS 2015 Specflow ver 1.9.0(我根据其他问题从2.1.0降级到这个没有帮助)
当我尝试构建我的项目时,它会出现以下错误:
我现在还没有问过一个问题,所以如果我错过了关于此的重要信息,请告诉我,我会更新.
提前致谢