You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project, I have set [assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
This makes it safe to use ctor/IDisposable to setup/teardown the test.
Sometimes, I need state, so then I can add [FixtureLifeCycleAttribute(LifeCycle.SingleInstance)] to my class.
However it may be I still have ctor/IDisposable on this class and forget to change it to [SetUp]/[TearDown]
I would like the analyzer to warn me about this situations (and autofix if possible)
It would also be great if the analyzer is aware of assembly level attributes, they may not be defined on the class.
The text was updated successfully, but these errors were encountered:
Could you please create a separate issue for the recognition of the assembly level attribute: [assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
In theory, even unit tests that are LifeCycle.SingleInstance can be disposable.
Most will use OneTimeSetUp and OneTimeTearDown, but doing the same actions in the constructor and Dispose is allowed.
When you say you need state, do you mean state between tests in the same fixture?
Note that moving items to [SetUp]/[TearDown] won't give you state and is the equivalent of constructor/Dispose
You only can get state with static fields which you initialize in OneTimeSetUp.
@manfred-brands Ah interesting, I didn't realize that when LifeCycle.SingleInstance, constructor takes the role of OneTimeSetUp, but it makes sense. I guess that makes it not suitable for the analyzer after all, since it cannot know the developers intention.
Hello
In my project, I have set
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
This makes it safe to use
ctor/IDisposable
to setup/teardown the test.Sometimes, I need state, so then I can add
[FixtureLifeCycleAttribute(LifeCycle.SingleInstance)]
to my class.However it may be I still have
ctor/IDisposable
on this class and forget to change it to[SetUp]/[TearDown]
I would like the analyzer to warn me about this situations (and autofix if possible)
It would also be great if the analyzer is aware of assembly level attributes, they may not be defined on the class.
The text was updated successfully, but these errors were encountered: