-
Notifications
You must be signed in to change notification settings - Fork 35
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
error NUnit1032 is incorrect when InstancePerTestCase and constructor is used to initialize IDisposible #756
Comments
The analyzer explicitly excludes Maybe there is an issue with detecting either of these, can you supply me with a small example? |
I'm not getting CA1001, although I think I definitely should be. I've made my TestFixture IDisposable and I assume Nunit will dispose after running each test if I have InstancePerTestCase. I suggest the help for this be updated to tell users if they are doing InstancePerTestCase they should make their test fixture disposable |
I have InstancePerTestCase specified at the assembly level. Not sure if that would make a difference. |
Yes, that would make a difference, the analyzer currently only looks at attributes on the Fixture itself. |
Yes I've changed my fixture to be IDisposable and the error disappeared. So I'm happy. Feel free to keep this open if you intend to make it check for assembly level attributes or update the help. Otherwise close it as I'm good to go. |
The NUnit.Analyzer complements to the Microsoft NET Analyzers. It knows about [...SetUp] and [...TearDown] which Microsoft doesn't.
Unfortunately, neither CA1001 nor CA2213 are enabled by default You will need to add/edit your
I leave this ticket open to update the documentation with the above. |
If you have the following:
Then you get the following error:
error NUnit1032: The field _yourService should be Disposed in a method annotated with [OneTimeTearDownAttribute] (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit1032.md)
However [OneTimeTearDownAttribute] must now be a static method and the IDisposible isn't and shouldn't be so it can't dispose it.
It seems this error doesn't know about InstancePerTestCase and so gets this wrong.
And no I don't want to create the IDisposible in a [Setup] method instead of the constructor. Putting it in the constructor allows me to make in non nullable and readonly. Which means I don't need null checks in every test.
The text was updated successfully, but these errors were encountered: