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

Static test context should not be used within instance methods #2370

Closed
Evangelink opened this issue Feb 19, 2024 · 0 comments · Fixed by #2597
Closed

Static test context should not be used within instance methods #2370

Evangelink opened this issue Feb 19, 2024 · 0 comments · Fixed by #2597

Comments

@Evangelink
Copy link
Member

Evangelink commented Feb 19, 2024

Summary

Assembly/Class initialize methods accept a TestContext instance as parameter. It's possible that some developers store this context in a field/property and then use this static instance in TestInitialize/TestCleanup, Dispose/DisposeAsync, in test methods or in methods providing arguments for parameterized tests. In the cases listed above, the user should instead use the instance TestContext property as it will contain up-to-date info related to current test while the static one will have only global information.

This rule should be enabled by default as Info as it won't cause any break to users but is definitely leading to some headache. On v4, we should consider bumping the severity to Warning.

Category of the rule should be usage.

Relates to #2051

AB#1986693

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

Successfully merging a pull request may close this issue.

2 participants