Skip to content

NUnit1032/NUnit3002 - local functions not analyzed #919

@PiotrKlecha

Description

@PiotrKlecha

Object creation and disposal inside local functions is not properly processed by NUnit1032 analyzer.

The following is considered invalid (despite being correct):

[TestFixture]
public class DisposableTest
{
    private IDisposable? disposable;

    [SetUp]
    public void SetUp()
    {
        disposable = new DisposableClass();
    }

    [TearDown]
    public void TearDown()
    {
        RunDispose();

        void RunDispose()
        {
            disposable.Dispose();
        }
    }
}

And the following passes (although the field is not disposed):

[TestFixture]
public class DisposableTest
{
    private IDisposable? disposable;

    [SetUp]
    public void SetUp()
    {
        Initialize();

        void Initialize()
        {
            disposable = new DisposableClass();
        }
    }

    [TearDown]
    public void TearDown()
    {
    }
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions