Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Xunit console output #644

Closed
wants to merge 2 commits into from
Closed

Conversation

darrencauthon
Copy link
Contributor

@darrencauthon darrencauthon commented Jun 12, 2016

fullscreen_061216_080905_am

fullscreen_061216_081831_am

@darrencauthon
Copy link
Contributor Author

darrencauthon commented Jun 12, 2016

I still need to get this class added into the generated test class:

        public class XUnitTraceListener : TechTalk.SpecFlow.Tracing.ITraceListener
        {
            private readonly Xunit.Abstractions.ITestOutputHelper testOutputHelper;

            public XUnitTraceListener(Xunit.Abstractions.ITestOutputHelper testOutputHelper)
            {
                this.testOutputHelper = testOutputHelper;
            }

            public void WriteTestOutput(string message)
            {
                testOutputHelper.WriteLine(message);
            }

            public void WriteToolOutput(string message)
            {
                testOutputHelper.WriteLine(message);
            }
        }
  • Add this to code generation:

I also need this code added to the constructor, adding the block of code above or below the TestInitialize call.

        public SpecFlowFeature1Feature(ITestOutputHelper testOutputHelper)
        {
            // starting here =>
            var traceListener = (TechTalk.SpecFlow.TestRunnerManager.GetTestRunnerManager()
                .GetType()
                .GetProperties().Where(x => x.Name == "GlobalContainer")
                .Select(x => x.GetValue(TechTalk.SpecFlow.TestRunnerManager.GetTestRunnerManager()))
                .FirstOrDefault()
                as IObjectContainer)
                .Resolve<ITraceListener>() as DefaultListener;
            if (traceListener != null)
            {
                var xUnitTraceListener = new XUnitTraceListener(testOutputHelper);
                traceListener.OverrideWith(xUnitTraceListener);
            }
            ///  ^^^^
            this.TestInitialize();
        }
  • Add this to code generation:
  • must get using System.Linq; added to the top

@darrencauthon
Copy link
Contributor Author

Taking another look at this... I don't think it's going to work the way it is.

We can't really touch the global container, I think... at least not with regards to a single instance of ITraceListener. I don't know how the Xunit ITestOutputHelper instance works, but assuming it is set up to be multi-threaded with all sorts of tests running, I wouldn't be surprised if the instance loaded into the global container would be changing as multiple tests are run. What would that do to the test results? Not sure.

I think it would make more sense to load the ITraceListener on a child container level, so each scenario would have its own instance. Then it would be a better fit, but that's not a fit for Bodi. Bodi will throw an error if anything has been registered. But what do we do to that, tack on another boolean to a Registration method? That's not good.

Still thinking about this...

@SabotageAndi
Copy link
Contributor

This is similar to NUnit3, or?
@dirkrombauts Did you do there already some work for the test output?

As far as I unterstood XUnit, we have to get the Xunit.Abstractions.ITestOutputHelper by constructor injection on the test class.
When we have it, we should probably register it in the ScenarioContainer.
After that, we could create a special TraceListener Implementation for XUnit.

The ITraceListener ist currently register in the global and the test thread container. In SpecFlow+Runner I am registering it also in the ScenarioContainer. So that would work.

@dirkrombauts
Copy link
Contributor

@SabotageAndi No, I didn't do anything to do with test output for NUnit 3 ...

@SabotageAndi
Copy link
Contributor

closed because of being outdated

@SabotageAndi SabotageAndi deleted the xunit_console_output branch July 2, 2019 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants