标签: specflow

Specflow:步骤的基类

我有一个奇怪的例子,执行顺序混乱

我为所有步骤定义创建了一个基类

public abstract class BaseSteps
{

    static BaseSteps()
    {
        Console.WriteLine("static Constructor");
    }

    protected BaseSteps()
    {
        Console.WriteLine("public Constructor");
    }


    [BeforeTestRun]
    public static void BeforeTestRun()
    {
        Console.WriteLine("static void BeforeTestRun");
    }

    [AfterTestRun]
    public static void AfterTestRun()
    {
        Console.WriteLine("static void AfterTestRun");
    }

    [Before]
    public static void Before()
    {
        Console.WriteLine("Base Before Scenario");
    }


}



 [Binding]
    public class SpecFlowFeature1Steps: BaseSteps
    {
    public SpecFlowFeature1Steps()
    {

    }
    [BeforeScenario()]
    public void Setup()
    {

    }
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,我的调试模式下的执行顺序看起来像这样

  1. 基类静态构造函数
  2. [测试运行之前]
  3. 基类构造函数
  4. 子类构造函数
  5. 子类[BeforeScenario]
  6. 基类 [BeforeScenario] ....

我原以为它会像...

  1. 基类[BeforeScenario]
  2. 基础构造函数
  3. 子类构造函数
  4. 子类[BeforeScenario] …

c# testing bdd specifications specflow

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

步骤类的 Specflow 容器尚未初始化

public class BaseSteps : Steps
{
    [BeforeFeature]
    public static void BeforeFeatureStep()
    {
        var otherStep = new OtherStep();
        otherStep.ExecuteStep();
    }
} 

public class OtherStep : Steps
{
    public void ExecuteStep() 
    {
        var key = 'key';
        var val = 'val';
        this.FeatureContext.Add(key, val);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一个示例片段。当我尝试访问时this.FeatureContext.Add(),出现异常Container of the steps class has not been initialized

对此的任何帮助表示赞赏。

c# xunit specflow

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

VS 2017 测试资源管理器窗口空引用异常

因此,基本上当我在 VS 2017 (15.3.2.) 中使用 nunit3 和 specflow、selenium UI 测试打开我的解决方案时,我在测试资源管理器窗口中收到以下异常和错误:

在此处输入图片说明

有没有办法来解决这个问题?有一个解决方法,但它很荒谬......如果我在没有任何项目的情况下启动 VS 2017,然后从最近打开项目 - 它的工作正常。

An exception was encountered while constructing the content of this frame.  This information is also logged in "C:\Users\USER\AppData\Roaming\Microsoft\VisualStudio\15.0_6ae63cad\ActivityLog.xml".

Exception details:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.InvokeSwapInRealTestWindow(String eventName)
   at Microsoft.VisualStudio.TestWindow.VsHost.TestWindowToolWindow.OnToolWindowCreated()
   at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, UInt32 flags)
   at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Type toolWindowType, Int32 id, ProvideToolWindowAttribute tool)
   at Microsoft.VisualStudio.Shell.Package.FindToolWindow(Type toolWindowType, Int32 id, Boolean create, ProvideToolWindowAttribute tool)
   at Microsoft.VisualStudio.Shell.Package.CreateToolWindow(Guid& toolWindowType, Int32 id)
   at …
Run Code Online (Sandbox Code Playgroud)

specflow nunit-3.0 visual-studio-2017

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

How to log with Nlog in SpecFlow?

SpecFlow writes its output into Console like this:

Given the "TestOperator" user is logged in
-> done: WebUserSteps.GivenTheUserIsLoggedIn("TestOperator", "") (9.5s)
Run Code Online (Sandbox Code Playgroud)

How can we make it use NLog to configure where it should write?

With this:

public class CustomListener : ITraceListener
{
    private Logger Log = LogManager.GetLogger("SPECFLOW");

    public void WriteTestOutput(string message)
    {
        Log.Trace(message);
    }

    public void WriteToolOutput(string message)
    {
        Log.Trace(message);
    }
}
Run Code Online (Sandbox Code Playgroud)

And

[Binding]
public class ScenarioContextInitializer 
{
    private readonly IObjectContainer _container;

    public ScenarioContextInitializer(ScenarioContext scenarioContext)
    {
        _container = (scenarioContext ?? throw …
Run Code Online (Sandbox Code Playgroud)

c# nlog xunit specflow

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

SpecFlow Visual Studio 扩展尝试使用 SpecFlow 代码隐藏生成器 1.9

尝试构建自动化解决方案时出现以下错误。因此,我目前无法更改我的功能文件中的任何内容。

错误版本冲突 - SpecFlow Visual Studio 扩展尝试使用 SpecFlow 代码隐藏生成器 1.9,但项目“POC.Specs”引用 SpecFlow 2.0。

错误 我们建议迁移到 MSBuild 代码隐藏生成来解决此问题。

错误有关更多信息,请参阅https://specflow.org/documentation/Generate-Tests-from-MsBuild/

.net 版本 4.6.2 Specflow 2.0.0 TestStack 白色 Visual Studio 2015

我尝试重新安装 specflow 2.0.0,但仍然存在同样的问题

任何帮助将非常感激。

.net c# bdd white-framework specflow

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

在“添加新项目”窗口中找不到 SpecFlow 功能文件选项 - VS20019

我是visual studio和specflow的新手。我的机器中有 Visual Studio 2019,我已按照所有步骤操作并通过 manage nuget package 成功安装了 specflow。我无法通过右键单击项目> 添加新项目来添加功能文件。我看不到 specflow 。任何人都可以帮助我如何添加功能文件?

c# visual-studio specflow selenium-webdriver

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

Specflow 未在 Visual Studio 2019 中执行测试

我对 Specflow 有一个非常奇怪的行为,它只适用于一名团队成员。其他人都没有问题。

VS2019 测试运行器正确显示所有规范流测试,但是当“运行所有测试”时,没有任何测试被执行,但有信息“没有可用的源”。Specflow 正确生成所有 cs 文件。

我尝试创建一个全新的解决方案,其中包含一个单元测试项目,向其中添加了规范流,创建了一个功能,生成了步骤并运行了所有测试。一切都按预期进行,测试已执行并成功。然后我将这个新的 csproj 添加到另一个不执行测试的解决方案中。奇怪的是,“新测试”在旧解决方案中也不起作用。

当项目团队的其他人克隆我们的存储库时,安装 specflow 对他们来说一切正常。在这个解决方案中只有这台机器。我已经尝试重新安装 VS2019。我们检查了解决方案中的每个项目是否具有相同的目标平台,我们尝试删除一些 %TEMP% 文件,但到目前为止没有任何效果。

NuGet 包:

  • SpecFlow v3.0.225
  • SpecFlow.MsTest v3.0.225
  • SpecFlow.Tools.MsBuild.Generation v3.0.225

c# unit-testing visual-studio specflow

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

xUnit : 多重断言或软断言

如何在 xUnit 中找到多个断言或软断言?我发现 Nunit 有以下能力,试图在 xUnit 中找到类似的选项。

Assert.Multiple(() =>
 {
   Assert.AreEqual(expectedResult1, actualResult1, "Mismatch in Score1!");
   Assert.AreEqual(expectedResult2, actualResult2, "Mismatch in Score2!");
   Assert.AreEqual(expectedResult3, actualResult3, "Mismatch in Score3!");
  });
Run Code Online (Sandbox Code Playgroud)

c# xunit specflow

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

VS2019 中的测试资源管理器显示 Specflow 测试“无可用源”

在 vs2019 测试资源管理器中,我的 Specflow 测试显示“无可用源”,因此双击不会最终进入实际的 Specflow 测试(功能文件)。这些单元测试是通过“Specflow.Tools.MsBuild.Generation”nuGet 包生成的。feature.cs 文件被 Git 忽略,并且不是我的项目文件的一部分。我能够运行它们,并且在构建后可以发现它们(通过 NUnit 3 测试适配器 Visual Studio 扩展)。

我尝试了多种解决方案,例如: - 升级到 sdk 样式项目(请参阅https://github.com/techtalk/SpecFlow/issues/1457#issuecomment-491497035) - 创建全新项目(完整框架)

任何帮助,将不胜感激!提前谢谢。

.net c# nunit specflow

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

目标进程退出时未引发 CoreCLR 启动事件 - 尝试在 Visual Studio 中运行基于硒的测试时输出错误

当我尝试在 Visual Studio 中运行自动化测试时,我似乎收到以下错误。我使用的测试提供程序是 SpecFlow.NUnit。有人有什么想法吗?我很困惑... 错误

错误文本:

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[19308] testhost.x86.exe: Program Trace' has exited with code 0 (0x0).
The program '[19308] testhost.x86.exe' has exited with code -2147450730 (0x80008096).
Run Code Online (Sandbox Code Playgroud)
  • 我有最新的 2019 版 Visual Studio
  • 目标框架是已安装的.NET Core 2.1

我安装了以下 NuGet 软件包和版本 Specflow NuGet 包 NUnit NuGet 包

c# nunit visual-studio specflow

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