我希望学习Gherkin,以便我可以使用specflow ; 我正在寻找我可以在火车上阅读的文件,例如在纸上打印.
我在网上找到的只是简短的断开连接的描述,不会讲故事,需要在网页之间进行大量点击才能阅读.
(我不介意买一个好的,如果它有很多好的小黄瓜内容)
是否可以在Specflow中跨多个场景轮廓共享一组通用示例,而无需复制每个轮廓的示例集?
例如,请原谅这个例子,但是这里Examples重复一遍Scenario Outline,我想知道是否有可能宣布Examples一次,并为每一个使用它们Scenario Outline?
Feature: Just an example about animals
Scenario Outline:
Given an <animal>
When something happens
Then this should be the outcome
Examples:
| animal |
| Dog |
| Cat |
Scenario Outline:
Given an <animal>
When something different happens
Then this other thing should be the outcome
Examples:
| animal |
| Dog |
| Cat |
Run Code Online (Sandbox Code Playgroud) 我有几个功能文件和一些场景.我需要忽略几个场景或功能,@tag根据某些条件标记一些.我已阅读specflow文档,但没有找到对我的解决方案有用的东西.我想用类似的东西
[BeforeScenario("sometag")]
public static void BeforeScenario()
{
if(IgnoreTests)
{
// This is the hot spot
Scenario.DoSomethingToIgnoreScenarioIfConditionButRunScenarioIfConditionFalse();
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试动态添加或删除标签
[BeforeScenario("sometag")]
public static void BeforeScenario()
{
if(IgnoreTests)
{
ScenarioContext.Current.ScenarioInfo.Tags.ToList().Add("ignore");
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.也许是否有其他方法可以动态添加或删除标签?或者ScenarioContext类中哪些方法会忽略当前场景?
我对 SpecFlow 有问题。我们正在使用 Azure Devops,当我在本地机器上构建解决方案时,它运行良好,但在 Azure Devops 构建期间,我收到以下错误:
[error]C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\specflow.tools.msbuild.generation\3.1.86\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): Error MSB4018: The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified.
File name: 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at …Run Code Online (Sandbox Code Playgroud) Silverlight Unit测试框架定义了一个处理异步调用的过程(从Microsoft.Silverlight.Testing.SilverlightTest派生测试类,添加异步属性,使用EnqueueXXX方法.)考虑SpecFlow在测试类和步骤之间的分离:
是否有可能有两个步骤定义类,第一个在一个命名空间/项目中,第二个在另一个中?我喜欢这个:
我运行的测试项目:namespace:ABZ.ExcelTest类名:ABZ.ExcelTest.ExcelStepDefinition
我的另一个项目是Logic for testing:namespace:ABZ.OfficeAddInTestLogic类名:ABZ.OfficeAddInTestLogic.StepDefinition
我的两个类都有[Binding]属性但是这个不在测试项目中的属性(ABZ.OfficeAddInTestLogic.StepDefinition)找不到,我得到NUnit错误:
找不到该步骤的匹配步骤定义.使用以下代码创建一个:...
是否有可能在不同的项目中有两个步骤定义类?
可能重复:
单元测试的SpecFlow/BDD?
在过去的几年里,我使用NUnit/Moq在TDD工作,在过去的几个月里,我一直在使用mSpec来处理BDD.
到目前为止这么好,但我们现在希望更多地转向基于验收标准的测试,其中涉及业务分析师,我们在开发过程中获得了外部.
所以现在我们已经预定义了Gherkin语法文件,并且使用specflow感觉它是正确的工作方式.
但是,在具有预定义Gherkin文件的单元测试级别将违背我对TDD的理解.换句话说,你的设计随着行为的不断深入改进你的设计.
由于我们正在使用外部方法,现在在单元测试级别可能是我们现在拥有现在可用于驱动我的单元测试的规范/行为(只是感觉它与我一直在做TDD的方式相反) )?
之前这些文件对验收测试很重要,但作为开发人员,我将独自工作,除非我使用SpecFlow,否则它们不是必需的.
当我们使用mspec时,我们在具有GWT文件的单元测试级别有什么好处?开发人员应该能够跳转到代码并阅读测试,或者只是运行测试运行器以查看它在做什么.
TIA JD
我试图从Visual Studio 2010命令提示符运行SpecFlow测试,我收到一个相当迟钝的错误消息:
单元测试适配器引发异常:无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.
有关我的VS2010项目设置的一些信息:
我有一个post-build事件,它将我的NuGet包目录中的一些DLL文件复制到目标目录:
copy $(SolutionDir)packages\SpecBind.1.2.1.71\lib\net45\SpecBind.dll $(TargetDir)
copy $(SolutionDir)packages\SpecBind.CodedUI.1.2.1.71\lib\net45\SpecBind.CodedUI.dll $(TargetDir)
Run Code Online (Sandbox Code Playgroud)
没有这个,mstest无法以某种方式加载许多SpecFlow程序集.
测试项目App.config的相关部分
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<section name="specBind" type="SpecBind.Configuration.ConfigurationSectionHandler, SpecBind" />
</configSections>
<connectionStrings>
...
</connectionStrings>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="MsTest" generatorProvider="Specflow.CodedUI.MsTestCodedUiGeneratorProvider, Specflow.CodedUI" runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTest2010RuntimeProvider, TechTalk.SpecFlow" />
<stepAssemblies>
<!-- This attribute is required in order to …Run Code Online (Sandbox Code Playgroud) 我刚开始使用SpecFlow并且非常喜欢这个工具.但是,我正在讨论与方案大纲中的示例数据输入相关的一些问题.
只是想知道我所面对的是正常的还是有一个技巧.
我正在使用C#Visual Studio 2013并使用下划线样式的步骤定义编写MVC应用程序.我也尝试过正则表达式样式,但仍然遇到类似的问题.
所以问题是我提供了用户名,密码等作为参数,并在我的示例中包含了示例数据.看来会发生以下情况: -
当第一次生成场景时,我必须在参数周围放置"",否则它根本不会被作为参数拾取.但是当从示例中传入数据时,我在传入数据的末尾得到一个"/".当我回到场景时,然后删除参数周围的"".这有点令人沮丧,但如果这是处理它的最佳方式,我可以忍受.只是想知道是否有人对这一点有任何建议.
下一个问题与数据本身有关.如果我的数据中有任何字符(如@或&等),那么它会在该点分割该数据并将其提供给下一个参数,这样我就会得到不正确的数据.
我已经在下面包含了我的代码 - 如果有人有任何建议或资源可以看,我将不胜感激.
功能文件 功能:AccountRegistration为了在我的组织中使用Mojito服务作为访客用户,我想创建一个具有管理privelages的帐户
Scenario Outline: Register with valid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will be logged in as <username>
And my account will be assigned the role of <role>
Examples:
| email | organisation | password | passwordConfirmation | username | role |
| …Run Code Online (Sandbox Code Playgroud) 我想拥有以下测试步骤类结构:
[Binding]
public class BaseStep
{
[Given(@"there is a customer")]
public void GivenThereIsACustomer(Table table)
{
HandleCustomer(table);
}
protected virtual void HandleCustomer(Table table)
{
}
}
[Binding]
public class FeatureOneStep : BaseStep
{
protected override void HandleCustomer(Table table)
{
// feature one action
}
[Given(@"feature one specific step")]
public void GivenFeatureOneSpecificAction(Table table)
{
// do something
}
}
[Binding]
public class FeatureTwoStep : BaseStep
{
protected override void HandleCustomer(Table table)
{
// feature two action
}
[Given(@"feature two specific step")]
public …Run Code Online (Sandbox Code Playgroud) specflow ×10
bdd ×3
c# ×3
gherkin ×3
tdd ×2
.net ×1
ambiguous ×1
asp.net-mvc ×1
azure-devops ×1
cucumber ×1
inheritance ×1
mspec ×1
mstest ×1
nunit ×1
rspec ×1
selenium ×1
silverlight ×1
testing ×1