-
Notifications
You must be signed in to change notification settings - Fork 289
Add analyzer for duplicate test method attributes (MSTEST0059) #7076
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Evangelink <[email protected]>
Co-authored-by: Evangelink <[email protected]>
| <value>Test method '{0}' has multiple attributes that inherit from 'TestMethodAttribute'. Only one test method attribute is allowed.</value> | ||
| </data> | ||
| <data name="DuplicateTestMethodAttributeDescription" xml:space="preserve"> | ||
| <value>A test method should be marked with exactly one attribute that is or inherits from 'TestMethodAttribute'. Having multiple such attributes can lead to unexpected behavior.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so much unexpected behavior. The problem is that only one attribute will be called (the first returned by reflection).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please update the messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the messages to clarify that only the first attribute returned by reflection will be used, rather than saying "unexpected behavior". Changes committed in b4de188.
Changed description from "unexpected behavior" to explicitly state that only the first attribute returned by reflection will be used when multiple TestMethodAttribute-derived attributes are present. Co-authored-by: Evangelink <[email protected]>
Methods decorated with multiple
TestMethodAttribute-derived attributes compile but only the first attribute returned by reflection will be used, which can be confusing. For example:Changes
Analyzer Implementation
DuplicateTestMethodAttributeAnalyzerthat detects methods with >1TestMethodAttribute-derived attributeResources & Localization
Resources.resx.xlflocalization files with new entriesAnalyzerReleases.Unshipped.mdTests
DataTestMethodcombinations, edge casesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.