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

Notification

Icon
Error

Fail tests when the fixture dispose throws
aignas
#1 Posted : Tuesday, June 26, 2018 8:30:57 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/24/2017(UTC)
Posts: 5
Location: Lithuania

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

I'm using XUnit with NCrunch (both are latest versions) and everything is really nice.

However, I recently had a hard to debug issue where the fixture was throwing in Dispose but the test was still marked as passed. Because it was not the behaviour on the build server, it was rather strange. I did not find an option to fail the tests if the fixture disposal throws, but it would be good to have something like this. For certain integration tests it is really important to have good disposal in the test fixtures, otherwise we may leak resources and crash not only NCrunch, but the infrastructure.

Something that illustrates what I mean:
Code:

public class TestFixture: IDisposable
{
    public void Dispose()
    {
        throw new NullReferenceException();
    }
}

public class TestsDependingOnFixture : IClassFixture<TestFixture>
{
    public TestsDependingOnFixture(TestFixture fixture)
    {
    }

    [Fact]
    public void ExampleTest()
    {
    }
}

public class TestFixtureTests
{
    [Fact]
    public void TestFixtureDisposal()
    {
        using(new TestFixture())
        {
            // should not throw
        }
    }
}
Remco
#2 Posted : Tuesday, June 26, 2018 9:24:57 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this problem.

You've managed to find a hole in NCrunch's handling here.

Xunit reports this problem using a specialised message, and we haven't been listening for it. The result is that NCrunch ignores the exception and pretends that it doesn't exist.

A fix for this will be out with NCrunch v3.18. Thanks for taking the time to report this problem.
2 users thanked Remco for this useful post.
eriove on 6/26/2018(UTC), aignas on 6/26/2018(UTC)
Remco
#3 Posted : Wednesday, August 1, 2018 8:18:34 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
The just released v3.18 includes a fix for this issue.
1 user thanked Remco for this useful post.
eriove on 8/1/2018(UTC)
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.029 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download