Skip to content
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

Request: Analyzer to error when non-static OneTimeSetup is used with [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] #629

Open
CoenraadS opened this issue Nov 7, 2023 · 2 comments

Comments

@CoenraadS
Copy link

CoenraadS commented Nov 7, 2023

As per the NUnit documentation

When using LifeCycle.InstancePerTestCase, the OneTimeSetUp and OneTimeTearDown methods must be static, and each are only called once. This is required so that the setup or teardown methods do not access instance fields or properties that are reset for every test.

I would like to see the analyzer detect the following:

  • Error: [FixtureLifeCycleAttribute(LifeCycle.InstancePerTestCase)] & non static [OneTimeSetUp]/[OneTimeTearDown]
    - Error: [FixtureLifeCycleAttribute(LifeCycle.SingleInstance)] & static [OneTimeSetUp]/[OneTimeTearDown]

It would also be great if the analyzer is aware of assembly level attributes, they may not be defined on the class.

@manfred-brands
Copy link
Member

Thanks @CoenraadS.

I agree the first part is a good rule to have.
The second though is technically valid, although unnecessary.
I have even seen fixtures were all tests are static. You can even have static fixtures.

@CoenraadS
Copy link
Author

Ah interesting. I updated my original issue so only the first one is requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants