Using xunit ITestOutputHelper context injection together with BeforeXXX hooks

658 views
Skip to first unread message

Alex van Vlerken

unread,
Mar 6, 2018, 12:25:42 PM3/6/18
to SpecFlow
Hello everyone,

I think I have found a bug in Specflow's XUnit support, but before I file a bug - I first want to check with this group.
When I create a specflow test project using Specflow 2.3.1 with the xUnit unitTestProvider, containing a dummy feature like this:
----
Feature: Something
Scenario: DummyScenario
----

and a Binding class similar to this:
----
[Binding]
public class MySteps
 {
    private ITestOutputHelper _testOutputHelper;
   
    public MySteps(ITestOutputHelper testOutputHelper)
    {
        _testOutputHelper = testOutputHelper;
    }

    [BeforeScenario]
    public void Before()
    {
    }
}
----

Then when I execute the test, It will fail with a "BoDi.ObjectContainerException" stating it cannot resolve "Xunit.Abstractions.ITestOutputHelper". However, when I remove the [BeforeScenario] attribute, it will run fine - and a valid xUnit ITestOutputHelper instance will be injected in the constructor.

Is there anyone who has seen something similar? Or maybe this is not a bug, but a configuration issue?

Best regards, Alex



Andreas Willich

unread,
Mar 6, 2018, 10:53:15 PM3/6/18
to spec...@googlegroups.com
Yes, it's a bug, Or more currently not working.
There is an open issue for this but for MSTest: https://github.com/techtalk/SpecFlow/issues/936

The reason this doesn't work is, that the container registration of the ITestOutputHelper is done after the hook is executed.

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex van Vlerken

unread,
Mar 7, 2018, 10:04:24 AM3/7/18
to SpecFlow
Thanks, I'll look into the github issue!
Reply all
Reply to author
Forward
0 new messages