Build/Test Issues

xUnit 2 beta 5 - support for ITestOutputHelper

Started by Inker on 9,253 views

Hi,

xUnit recently (some would say finally) added proper support for writing output/debug messages during testruns.

This is done via a constructor injected object. Unsurprisingly nCrunch currently does not understand this, and simply reports:


This test was not executed during a planned execution run. Ensure your test project is stable and does not contain issues in initialisation/teardown fixtures.


I realize xUnit2 is still in beta and is changing internally all the time. This post is just a ping to you so that you are aware of it.

Full sample below (works correctly in xUnit supplied VS testrunner, and resharper xUnit test provider).

using Xunit;
using Xunit.Abstractions;

namespace NCrunchTest
{
    public class TestOutputPlayground
    {
        private readonly ITestOutputHelper output;
        public TestOutputPlayground(ITestOutputHelper output)
        {
            this.output = output;
        }

        [Fact]
        public void Output()
        {
            output.WriteLine("hello from outputHelper");
        }
    }
}
Just posting this for others here, there is "quick" workaround for this for people who have updated to beta 5 and still want to use nCrunch:

Basically you can use conditional compilation when under NCrunch to manipulate the Testclass so that it looks like ITestOutputHelper is a ClassFixture.
Then you also need to provide your own outputhelper implementation (this can just write to Console or Debug or something). If this is under the same namespace as the Testclass
it will take precedence and the compiler will bind against it instead of the xUnit interface.

I made a little abstract baseclass so I don't have to do this for all testsclasses.


namespace NCrunchTest
{
    using Xunit.Abstractions;

#if NCRUNCH
    using System;
    public class ITestOutputHelper
    {
        public void WriteLine(string m) { Console.WriteLine(m); }
        public void WriteLine(string format, params object[] args){ Console.WriteLine(format, args); }
    }   
#endif

    public abstract class XUnitTests
#if NCRUNCH
        : Xunit.IClassFixture<ITestOutputHelper>
#endif
    {
        protected readonly ITestOutputHelper Output;
        protected XUnitTests(ITestOutputHelper output)
        {
            Output = output;
        }
    }
}

Post a reply

Log in to reply.