Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

xUnit 2 beta 5 - support for ITestOutputHelper
Inker
#1 Posted : Saturday, November 29, 2014 4:55:59 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/9/2014(UTC)
Posts: 17
Location: Austria

Thanks: 6 times
Was thanked: 4 time(s) in 4 post(s)
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:

Quote:

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).
Code:

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");
}
}
}
1 user thanked Inker for this useful post.
Remco on 11/29/2014(UTC)
Inker
#2 Posted : Saturday, November 29, 2014 5:39:33 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/9/2014(UTC)
Posts: 17
Location: Austria

Thanks: 6 times
Was thanked: 4 time(s) in 4 post(s)
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.

Code:

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;
}
}
}
1 user thanked Inker for this useful post.
Remco on 11/29/2014(UTC)
Remco
#3 Posted : Friday, December 19, 2014 5:34:08 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,986

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Just a heads up on this one. There is now an early build of NCrunch 2.11 that includes integration with Xunit v2 beta 5 - http://blog.ncrunch.net/post/Engine-Separation-and-VS2015-Integration.aspx.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.028 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download