NUnit1032 false positive in LifeCycle.InstancePerTestCase
test fixture using constructor
#595
Milestone
LifeCycle.InstancePerTestCase
test fixture using constructor
#595
Hi all,
First of all, thank you for the great work you've been doing on this library. It's much appreciated.
It seems the new rule NUnit1032 introduced in
v3.7.0
is flagging false positives and the wrong fix suggestion when dealing with test fixtures withLifeCycle.InstancePerTestCase
and constructors.Works as expected with
LifeCycle.SingleInstance
It works as expected with
LifeCycle.SingleInstance
. Given this disposable class:and this
LifeCycle.SingleInstance
failing fixture class:The suggested fix works:
LifeCycle.InstancePerTestCase
introduces some issuesHowever, if we switch to
LifeCycle.InstancePerTestCase
.The first issue is that a OneTimeTearDownAttribute needs to be static when using
LifeCycle.InstancePerTestCase
as it only runs once per test fixture, which prevents the disposal of the non-static field as suggested by the fix.The second problem is that doing a disposal in
[TearDown]
does not remove the NUnit1032 violation, which I believe it should as it's called after the execution of every test as inConstructor > test > Teardown
:The following does work, but then we lose some of the benefits of the constructor (e.g. readonly fields) and we need to disable nullability warnings (or disable/handle it in the tests or global level in
.editorconfig
or similar).The text was updated successfully, but these errors were encountered: