Skip to content

IDisposable not working with InstancePerTestCase #3773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pepone opened this issue Feb 20, 2021 · 2 comments · Fixed by #3804
Closed

IDisposable not working with InstancePerTestCase #3773

pepone opened this issue Feb 20, 2021 · 2 comments · Fixed by #3804
Labels
is:bug requires:releasenotes Issues that should be included in the release notes
Milestone

Comments

@pepone
Copy link

pepone commented Feb 20, 2021

using System;
using System.Buffers;
using NUnit.Framework;

namespace Foo
{
    [FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
    [TestFixture(256)]
    [TestFixture(1024)]
    [Parallelizable(scope: ParallelScope.All)]
    public class FixtureTests : IDisposable
    {
        private byte[] _buffer;

        public FixtureTests(int bufferSize) => _buffer = ArrayPool<byte>.Shared.Rent(bufferSize);

        public void Dispose() => ArrayPool<byte>.Shared.Return(_buffer);

        [TestCase(0)]
        [TestCase(256)]
        public void Foo_Test(int size)
        {
            Assert.AreEqual(size, size);
        }
    }
}

I would expect the above to create and dispose the fixture per test case but it is resulting in an exception from NUnit

Failed Foo_Test(0) [127 ms]
  Error Message:
   System.InvalidOperationException : DisposeFixtureCommand does not apply neither to TestMethod, nor to ParameterizedMethodSuite
  Stack Trace:
     at NUnit.Framework.Guard.OperationValid(Boolean condition, String message)
   at NUnit.Framework.Internal.Commands.DisposeFixtureCommand..ctor(TestCommand innerCommand)
   at NUnit.Framework.Internal.Execution.SimpleWorkItem.MakeTestCommand()
   at NUnit.Framework.Internal.Execution.SimpleWorkItem.PerformWork()

isn't this expected to work this way?

@rprouse rprouse added the is:bug label Feb 21, 2021
@feryatolcay
Copy link

Hi @rprouse
Did you find the problem. I have same problem now and I don't know why?
Thanks

@rprouse
Copy link
Member

rprouse commented Mar 1, 2021

We haven't got to this yet, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:bug requires:releasenotes Issues that should be included in the release notes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants