Skip to content

Conversation

@AtolagbeMuiz
Copy link
Contributor

This pull request fixes #6813

This new analyzer implementation allows similar unit test methods with different names within the same test class to be detected as duplicates.

NB: Because this is a new analyzer feature, I declared a new DIagnosticId value of MSTEST0059 as DoNotDuplicateTestMethodRuleId

namespace MSTest.Analyzers;

/// <summary>
/// MSTEST0033: <inheritdoc cref="Resources.DoNotDuplicateTestMethodTitle"/>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// MSTEST0033: <inheritdoc cref="Resources.DoNotDuplicateTestMethodTitle"/>.
/// MSTEST0059: <inheritdoc cref="Resources.DoNotDuplicateTestMethodTitle"/>.

context => CollectTestMethod(context, testClassAttributeSymbol, testMethodAttributeSymbol, testMethodsFound),
SymbolKind.Method);

compilationContext.RegisterCompilationEndAction(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of being compilation end, can it instead of a symbol start/end analyzer? You first RegisterSymbolStartAction for named types, then RegisterOperationBlockAction to analyze the individual methods, and then RegisterSymbolEndAction to do the final analysis of the collected methods?

private static SyntaxNode? GetMethodBody(SyntaxNode methodNode)
{
// Try block body first
System.Reflection.PropertyInfo? bodyProperty = methodNode.GetType().GetProperty("Body");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using reflection here doesn't seem like a good idea. This also actually might fail for VB which the analyzer claims to support

Comment on lines +200 to +203
for (int i = 0; i < methods.Count; i++)
{
for (int j = i + 1; j < methods.Count; j++)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like very extensive computations. Probably there is something we can do better here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyrusNajmabadi if you can suggest something here please. This PR attempts to implement #6813

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

Successfully merging this pull request may close these issues.

[Analyzer suggestion]: Duplicate test methods

2 participants