c# - 如何使用 TechTalk.SpecFlow 和 C# 以编程方式验证测试失败?

标签 c# specflow acceptance-testing

我想在 [Binding] 属性标记类的测试失败后执行 [AfterTestRun] 属性标记方法。我怎样才能实现这样的目标:

[Binding]
public class TestsRunner
{
   [AfterTestFails] // There is no such attribute
   public static void DoStuff()
   {

   }
}

[Binding]
public class TestsRunner
{
   [AfterTestRun]
   public static void DoStuff()
   {
        if(ScenarioContext.Current.TestHasFailed) // There is no such property
        {
            // Do stuff
        }  
   }
}

最佳答案

阅读一些文档后here我找到了下一个解决方案:

[Binding]
public class TestsRunner
{
    [AfterScenario]
    public void TakeScreenShot()
    {
        if(ScenarioContext.Current.TestError != null)
        {
            WebBrowser.TakeScreenShot(); // Your custom browser take screenshot method 
        }
    }
}

关于c# - 如何使用 TechTalk.SpecFlow 和 C# 以编程方式验证测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21839018/

相关文章:

c# - 不以某些文字开头的 ASP.NET MVC 路由

c# - 当没有当前项时,如何禁用绑定(bind)到当前项的 ICommand 的按钮?

java - Fitnesse Maven 类路径错误

jenkins - 我将如何在 CI 中创建包含大量服务的 docker 环境

c# - 将 XElement 转换为字符串

c# - EF Core - 在上一个操作完成之前,在此上下文中启动了第二个操作。不保证任何实例成员都是线程安全的

c# - 在表中找不到列名关键字

visual-studio-2015 - VS2015 specrun 集成

c# - Mono 和 Specflow - 命名空间 `TestCaseAttribute' 中不存在 `NUnit.Framework'

ruby - 我如何最好地在 Cucumber 中表达这种依赖于时间的场景?