Skip to content

IDisposable not working with InstancePerTestCase #3773

Closed

Description

@pepone
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?

Activity

  1. feryatolcay commented on Mar 1, 2021

    @feryatolcay

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

  2. rprouse commented on Mar 1, 2021

    @rprouse
    Member

    We haven't got to this yet, sorry.

  3. added this to the 3.13.2 milestone on Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions