Build/Test Issues

Exceptions from XUnit v3 IClassFixture are swallowed

Started by Fresa on 1,512 views

Exceptions thrown when disposing a class fixture seems to be ignored by ncrunch:

using Xunit;

namespace Example;

public class Test : IClassFixture<Fixture>
{
    [Fact]
    public void Test1()
    {
            
    }
}
    
public class Fixture : IAsyncLifetime
{
    public ValueTask DisposeAsync()
    {
        throw new Exception("Fail!");
    }

    public ValueTask InitializeAsync()
    {
        return ValueTask.CompletedTask;
    }
}


This test (and the class fixture) will pass when running it with ncrunch.

Running the same test with Rider's test runner the test succeeds, but it fails for the class fixture, as expected:
Class cleanup failed
[img]null[/img]
Xunit.Sdk.TestPipelineException
Class fixture type 'Example.Fixture' threw in DisposeAsync
   at Xunit.v3.FixtureMappingManager.<>c__DisplayClass13_0.<<DisposeAsync>b__0>d.MoveNext() in /_/src/xunit.v3.core/Utility/FixtureMappingManager.cs:line 82
--- End of stack trace from previous location ---
   at Xunit.v3.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.v3.core/Exceptions/ExceptionAggregator.cs:line 124
   at Xunit.v3.ExceptionAggregator.ThrowIfFaulted() in /_/src/xunit.v3.core/Exceptions/ExceptionAggregator.cs:line 167
   at Xunit.v3.FixtureMappingManager.DisposeAsync() in /_/src/xunit.v3.core/Utility/FixtureMappingManager.cs:line 99
   at Xunit.v3.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.v3.core/Exceptions/ExceptionAggregator.cs:line 124


NCrunch for Jetbrains Rider: v5.14.0.5
JetBrains Rider 2025.1.1, Build #RD-251.23774.471, built on April 28, 2025
.NET 9
<PackageReference Include="xunit.v3" Version="2.0.2" />
Thanks for sharing this issue. I've reproduced it as described.

The actual execution of tests and consolidation of results is handled inside Xunit itself, so NCrunch is walled away from this. I'm not sure right now why the behaviour is different. I'll raise this with the Xunit team to see if they have any ideas as to what could cause this.
I've prepared a build containing a fix for this issue. Would you be interested in giving it a try?

NCrunch_Console_5.15.0.3.msi
NCrunch_Console_5.15.0.3.zip
NCrunch_GridNodeServer_5.15.0.3.msi
NCrunch_GridNodeServer_5.15.0.3.zip
NCrunch_LicenseServer_5.15.0.3.zip
NCrunch_Rider_5.15.0.3.7z
NCrunch_Rider_5.15.0.3.zip
NCrunch_VS2010_5.15.0.3.msi
NCrunch_VS2010_5.15.0.3.zip
NCrunch_VS2012_5.15.0.3.msi
NCrunch_VS2012_5.15.0.3.zip
NCrunch_VS2013_5.15.0.3.msi
NCrunch_VS2013_5.15.0.3.zip
NCrunch_VS2015_5.15.0.3.msi
NCrunch_VS2015_5.15.0.3.msi.7z
NCrunch_VS2015_5.15.0.3.zip
NCrunch_VS2017_5.15.0.3.msi
NCrunch_VS2017_5.15.0.3.msi.7z
NCrunch_VS2017_5.15.0.3.zip
NCrunch_VS2019_5.15.0.3.msi
NCrunch_VS2019_5.15.0.3.msi.7z
NCrunch_VS2019_5.15.0.3.zip
NCrunch_VS2022_5.15.0.3.msi
NCrunch_VS2022_5.15.0.3.msi.7z
NCrunch_VS2022_5.15.0.3.zip

Post a reply

Log in to reply.