문제

I want to do execute [AfterTestRun] attribute marked method after test fails of [Binding] attribute marked class. How can I achieve something like:

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

   }
}

or

[Binding]
public class TestsRunner
{
   [AfterTestRun]
   public static void DoStuff()
   {
        if(ScenarioContext.Current.TestHasFailed) // There is no such property
        {
            // Do stuff
        }  
   }
}
도움이 되었습니까?

해결책

After reading some documentation here I have found the next solution:

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

다른 팁

As you say, these things don't exist. That's probably because you are trying to do something with SpecFlow that it has not been designed to do.

Don't forget all SpecFlow does is to bridge the gap between what a Unit testing framework (like NUnit, XUnit or MSTest) does and supporting plain text scenarios in a Gherkin format.

If you want to do these things that relate to the running of the test, then you probably need to look at the Unit test framework, or more likely, build your own test runner.

BTW, what is it that you actually want to do?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top