Build/Test Issues

Xunit and Skip breaking the runner

Started by enkafan on 16,587 views

I have some unit tests I need to skip so I was going to use a custom FactAttribute. This is causing the unit test discovery to throw an exception. I'm pretty sure this is an Xunit problem not an Ncrunch bug, but between the VS test runner, R# and teamcity I'm only seeing problems in NCrunch so I suspect it's a combo of an exception being thrown by xUnit that NCrunch could handle better. NCrunch failed to find ANY tests at all in a project with this attribute and crashed hard with the bug in the discoverer for that one test.

Edit : when I wrote this I thought the xUnit prerelease version of the runner was working, but I lied. I think I just got a false positive as I was switching out nuget packages

Exception is

An error occurred while analysing this project after it was built: System.Exception: Error while discovering test 'XunitSkip.UnitTests.Skip_test':System.InvalidOperationException: Sequence contains more than one element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Xunit.Sdk.XunitTestCase.Initialize()
   at Xunit.Sdk.TestMethodTestCase.EnsureInitialized()
   at Xunit.Sdk.TestMethodTestCase.get_SkipReason()
   at nCrunch.Module.XUnit2.Integration.XUnitDiscoveryMessageSink.discoverTest(ITestCase testCase, Object[] arguments)
   at nCrunch.Module.XUnit2.Integration.XUnit2TestFramework.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName)
   at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, TestFrameworkDescription[] frameworks, ComponentUniqueName testComponentUniqueName)
   at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(TestFrameworkDescription[] applicableFrameworks, ComponentUniqueName testComponentUniqueName)


App to reproduce is pretty simple. New console app, add xunit 2.0 and the Visual Studio Runner

using Xunit;

namespace XunitSkip
{
    public class UnitTests
    {
        [Fact]
        public void Whatever()
        {
            Assert.True(true);
        }

        [Fact]
        [Skip("skipping it")]
        public void Skip_test()
        {
            Assert.True(true);
        }        
    }

    public sealed class SkipAttribute : FactAttribute
    {
        public SkipAttribute(string reason = "just cause")
        {
            Skip = reason;
        }
    }
}

Edited

ok, my problem with xunit was human error on my part. I'm obviously throwing two facts on there which was blowing it up. Still would have been nice if this would have been marked as a failed test rather than preventing the whole assembly from failing

Post a reply

Log in to reply.