标签: specflow

如何并行运行 SpecFlow 测试

我尝试使用 NUnit 测试运行程序并行运行 SpecFlow 测试。我在用:

  • C#/.Net Core 3.1
  • NUnit 作为测试运行程序
  • 光谱流

我已在文件顶部添加了这一行(如下所述: https: //specflow.org/documentation/parallel-execution/):

[assembly: Parallelizable(ParallelScope.All)]
Run Code Online (Sandbox Code Playgroud)

测试开始并行执行,但立即抛出错误:

Message: 
    System.ArgumentException : An item with the same key has already been added. Key: NUnitTestProject1.SpecFlowFeature1Steps
Stack Trace: 
    Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
    Dictionary`2.Add(TKey key, TValue value)
    TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
    ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
    ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
    ObjectContainer.Resolve(Type typeToResolve, String name)
    TestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer container)
    lambda_method(Closure , IContextManager , Int32 )
    BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing mstest specflow .net-core

5
推荐指数
1
解决办法
5103
查看次数

将 ITestOutputHelper 与 Selenium、xUnit 和 C# 结合使用

我最近将一个项目从 NUnit 切换到 xUnit,以便可以使用 ITestOutputHelper 输出到日志。

该项目是一个相当标准的布局

功能文件->步骤类->页面类->帮助类。在辅助类中我们还有 hooks.class。我正在使用 xUnit 运行程序。

所以在我的 hooks 类中我创建了这个

private readonly ScenarioContext _scenarioContext;
private ITestOutputHelper _testOutputHelper;

public Hooks(ScenarioContext scenarioContext, ITestOutputHelper testOutputHelper)
{
    _scenarioContext = scenarioContext;
    this._testOutputHelper = testOutputHelper;
}

public void WriteOutput(string theMessage)
{
    _testOutputHelper.WriteLine(theMessage);
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题是如何从其他类访问 WriteOutput 函数?或者我把它放在错误的班级里了?

c# selenium automated-tests xunit specflow

5
推荐指数
1
解决办法
6485
查看次数

NUnit3TestExecutor 使用当前发现模式、显式运行发现了 1 个 NUnit 测试用例中的 0 个

当我从测试资源管理器运行 SpecFlow+NUnit 测试时,即使我只选择了部分测试,所有测试也会始终运行。

我还看到了这条消息,我怀疑它是相关的:

NUnit3TestExecutor discovered 0 of 1 NUnit test cases using Current Discovery mode, Explicit run
Run Code Online (Sandbox Code Playgroud)

此外,测试运行后,即使成功,它们仍被标记为“未运行”。

我该如何解决这个问题?

c# nunit specflow visual-studio-2019

5
推荐指数
1
解决办法
4540
查看次数

SpecFlow自定义工具"SpecFlowSingleFileGenerator"

我发现这个自定义工具用于从SpecFlow的.feature文件生成.cs文件.有没有办法在VS之外使用这个工具?在使用NAnt构建项目时,我想从控制台调用此工具以获取特定的.feature文件.

问候,

瓦伊达弗拉基米尔

specflow

4
推荐指数
1
解决办法
9483
查看次数

为什么specflow的示例总是使用UI

我是BDD的新手试图了解它..我对BDD的理解是......

"它是一种测试,用户的规范用于从业务中生成有价值的语言"

但是这些例子我只能看到UI的例子..就像当按下按钮时...当用户输入文本时...这不会形成我可以在我的代码中使用的语言..

我理解这个概念是错误的

specflow

4
推荐指数
1
解决办法
664
查看次数

SpecFlow - 用列表重复测试X次?

Scenario: Change a member to ABC 60 days before anniversary date
    Given Repeat When+Then for each of the following IDs:
    | ID         |
    | 0047619101 |
    | 0080762602 |
    | 0186741901 |
    | 0311285102 |
    | 0570130101 |
    | 0725968201 |
    | 0780265749 |
    | 0780265750 |
    | 0780951340 |
    | 0780962551 |
#-----------------------------------------------------------------------
    When these events occur:
    | WorkflowEventType   | WorkflowEntryPoint |
    | ABC                 | Status Change      | 
    Then these commands are executed:
    | command name      |
    | TerminateWorkflow …
Run Code Online (Sandbox Code Playgroud)

specflow

4
推荐指数
1
解决办法
2980
查看次数

SpecFlow辅助 - 从表创建实例

我正在尝试specFlow辅助,不知道如何从表创建类属性.想象一下,我有这堂课:

public class Tracking 
{
    public string Category { get; set; }
}

public class ODARequest
{
    public string Title { get; set; }
    public string Name { get; set; }
    public Tracking Tracking { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的给定场景是下一个:

Scenario: Successfully create an account
Given I have entered the following data into the ODA form:
    | Field                  | Value            |
    | Title                  | Mr               |
    | Name                   | Andy             |
    | Tracking Category      | MDA              |


public void GivenIHaveEnteredTheFollowingDataIntoTheODAForm(Table …
Run Code Online (Sandbox Code Playgroud)

specflow

4
推荐指数
2
解决办法
4752
查看次数

在步骤中调用步骤的Specflow会导致"无匹配步骤定义"错误

我遵循这里概述的技术

使用定义的步骤

[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
   Given("some condition");
   And("some action");
   When("some result");
}
Run Code Online (Sandbox Code Playgroud)

从像这样的场景

Scenario: Some dependant scenario
Given some condition 
And some base scenario has happened
When some other action
Then some other result
Run Code Online (Sandbox Code Playgroud)

然而这一步

  When some other condition
Run Code Online (Sandbox Code Playgroud)

产生以下错误 - >找不到该步骤的匹配步骤定义.使用以下代码创建一个:

[When(@"some other condition")]
public void Whensome other condition()
{
ScenarioContext.Current.Pending();
}
Run Code Online (Sandbox Code Playgroud)

我可以通过让基本场景仅使用Given来解决问题

[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
   Given("some condition");
   Given"some action");
   Given("some result");
}
Run Code Online (Sandbox Code Playgroud)

但这不是我应该做的.我错过了什么吗?为什么不能使用AND调用基本场景?

specflow

4
推荐指数
2
解决办法
8119
查看次数

在Specflow步骤中组织代码

我从Techtalk上了解到,将步骤定义与功能耦合是一种反模式。但是,我想知道如何组织步骤定义,以便在代码中轻松看到哪些步骤组合在一起。

例如,我应该为每个功能创建一个代码文件,为共享的步骤创建一个单独的文件吗?还是应该有一套功能的代码文件?

specflow

4
推荐指数
1
解决办法
1396
查看次数

无法识别的元素unitTestProvider

我是SpecFlow的新手,并使用SpecFlow软件包和SpecFlow附加软件包(NUnit随附)的基本功能进行了安装安装。

添加功能文件后,我在使用自定义工具生成SpecFlowsingleFilegenerations时遇到了一些问题(并且通过从属性中删除选项来解决了这些问题)

然后,当我重建解决方案时。它在unittestprovider的appconfig文件中显示了一些无法识别的元素

错误:[SpecFlow] System.Configuration.ConfigurationErrorsException:无法识别的元素'unitTestProvider'。

我的appconfig文件specflow部分

<specFlow>
    <unitTestProvider name="NUnit" />
    <plugins>
      <add name="Baseclass.Contrib.SpecFlow.Selenium.NUnit" path="..\packages\Baseclass.Contrib.SpecFlow.Selenium.NUnit.1.3.1\tools" /> 
    </plugins>

  </specFlow>
Run Code Online (Sandbox Code Playgroud)

c# selenium specflow

4
推荐指数
1
解决办法
1761
查看次数