1

Using MVS 2015/ Speckflow (2.4.1)/ xUnit (2.0.0) Please help to printout anything from static method with xUnit framework:

namespace UnitTestProject2
{
    [Binding]
    public class SpecFlowHooks
    {

        private readonly ITestOutputHelper output;

        public SpecFlowHooks(ITestOutputHelper output)
        {
            this.output = output;
        }

        [BeforeFeature]
        public static void BeforeFeature()
        {
            Console.WriteLine("~~~~~~~ calling BeforeFeature");
        }

        [AfterFeature]
        public static void AfterFeature()
        {
            Debug.WriteLine("~~~~~~~ calling AfterFeature");
        }

        [BeforeScenario]
        public void BeforeScenario()
        {
            output.WriteLine("~~~~~~~ calling BeforeScenario");
        }

        [AfterScenario]
        public void AfterScenario()
        {
            output.WriteLine("~~~~~~~ calling AfterScenario");
        }
    }
}

Result StandardOutput:

calling BeforeScenario
entered number: 50
entered number: 70
Add button pressed
Test passed
calling AfterScenario

As you can see, there's no output from static methods.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Alexander
  • 11
  • 1
  • Try to add the ITestOutputHelper as parameter to the Before/AfterFeature static method. I think SpecFlow will inject the argument when calling the hook. – Tz_ Jun 09 '20 at 14:36
  • Hi, after updating methods to: [BeforeFeature] public static void BeforeFeature(ITestOutputHelper output) { Console.WriteLine("~~~~~~~ calling BeforeFeature"); output.WriteLine("~~~~~~~ calling BeforeFeature"); } got the following: BoDi.ObjectContainerException : Interface cannot be resolved: Xunit.Abstractions.ITestOutputHelper ---- The following constructor parameters did not have matching fixture data: FixtureData fixtureData – Alexander Jun 09 '20 at 15:24
  • Sorry, you're right. There is no way to access the ITestOutputHelper in BeforeFeature. I think this is because xUnit does not provide it before the test (scenario) is running. You could search for a corresponding xUnit issue: how to access the ITestOutputHelper (or how to log in general) in an IClassFixture? – Tz_ Jun 10 '20 at 12:37

0 Answers0