-
Notifications
You must be signed in to change notification settings - Fork 275
Mark DataTestMethodAttribute as obsolete and add analyzer/codefix #5706
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: Youssef1313 <[email protected]>
Co-authored-by: Youssef1313 <[email protected]>
Co-authored-by: Youssef1313 <[email protected]>
[DataTestMethod]
in favor of [TestMethod]
} | ||
else | ||
{ | ||
// Only DataTestMethod exists - replace with TestMethod |
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.
Assume that this is always the case and delete the logic of "remove DataTestMethod"
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.
Simplified the logic as requested. The code fix now always replaces [DataTestMethod] with [TestMethod] regardless of whether both attributes exist together. Removed the complex branching logic and the RemoveAttributeAsync method. Fixed in commit 78f5305.
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.
Revert changes in this file.
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.
Reverted changes to DataTestMethodAttribute.cs as requested. The implementation now uses a purely analyzer-based approach without modifying the runtime attribute. Fixed in commit 8687172.
…taTestMethod with TestMethod Co-authored-by: Youssef1313 <[email protected]>
Co-authored-by: Youssef1313 <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
src/Analyzers/MSTest.Analyzers.CodeFixes/PreferTestMethodOverDataTestMethodFixer.cs
Outdated
Show resolved
Hide resolved
…nalyzer and code fix Co-authored-by: Youssef1313 <[email protected]>
continue; | ||
} | ||
|
||
if (context.Document.Project.Language == LanguageNames.CSharp) |
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.
Remove this condition. It's always true.
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.
Removed the redundant condition as requested. Since the CodeFixProvider only exports for C#, the language check was always true. Simplified the implementation by moving the logic directly into RegisterCodeFixesAsync and removing the unnecessary method. Fixed in commit 33c71b0.
} | ||
} | ||
|
||
private static Task RegisterCSharpCodeFixesAsync(CodeFixContext context, SyntaxNode root, SyntaxNode diagnosticNode) |
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.
This always return completed task. Make the return type void instead.
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.
Changed the method to be synchronous and return Document
directly instead of Task<Document>
. Removed the unused CancellationToken
parameter and updated the call site accordingly. Fixed in commit a260b1b.
…TestMethodFixer Co-authored-by: Youssef1313 <[email protected]>
… task Co-authored-by: Youssef1313 <[email protected]>
This PR implements the analyzer/codefix approach for obsoleting
[DataTestMethod]
in favor of[TestMethod]
as discussed in issue #4166.Changes Made
1. Mark DataTestMethodAttribute as Obsolete
[Obsolete]
attribute toDataTestMethodAttribute
with diagnostic IDMSTEST0044
[TestMethod]
instead2. New Analyzer: PreferTestMethodOverDataTestMethodAnalyzer
[DataTestMethod]
attributeMSTEST0044
3. New Code Fix Provider: PreferTestMethodOverDataTestMethodFixer
[DataTestMethod]
exists → Replace with[TestMethod]
[TestMethod]
and[DataTestMethod]
exist → Remove[DataTestMethod]
4. Comprehensive Test Coverage
[DataTestMethod]
usage[DataTestMethod]
with parameterized testsExample
Before:
After (with code fix):
This provides a smooth migration path for users while maintaining full backward compatibility until the attribute is removed in v4.
Fixes #4166.
💡 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.