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

Notification

Icon
Error

Exceptions from XUnit v3 IClassFixture are swallowed
Fresa
#1 Posted : Thursday, May 15, 2025 11:07:18 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/7/2018(UTC)
Posts: 3
Location: Sweden

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Exceptions thrown when disposing a class fixture seems to be ignored by ncrunch:

Code:
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:
Code:
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" />
Remco
#2 Posted : Thursday, May 15, 2025 11:39:16 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,288

Thanks: 986 times
Was thanked: 1324 time(s) in 1228 post(s)
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.
Remco
#3 Posted : Friday, May 16, 2025 5:06:57 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,288

Thanks: 986 times
Was thanked: 1324 time(s) in 1228 post(s)
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.035 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download