Skip to content

[Tech Debt] Code Duplication Analysis #9499

Closed

Description

@github-actions

Code Duplication Analysis

Auto-generated by the dedup-analysis workflow

Overview

Metric Value
Total clones 442
Duplicated lines 6022
Duplication % 3.896851845860161%
Source files scanned 1253
Findings analyzed 20

Analysis

Priority File A File B Lines Classification Approach Risk
High Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestRunSettings.cs Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/RunSettingsPatcher.cs 51 Extract Method Extract the duplicated logic into a shared helper library or common project used by both Adapter and VSTestBridge to reduce maintenance. Medium
High Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestRunSettings.cs Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/RunSettingsPatcher.cs 33 Extract Method Same as above; consolidate duplicated run settings patching code into a shared helper to avoid divergence. Medium
Medium Adapter/MSTestAdapter.PlatformServices/Helpers/ReflectHelper.cs Adapter/MSTestAdapter.PlatformServices/Services/ReflectionOperations.cs 32 Extract Method Refactor reflection helper methods into a shared helper class or project within MSTestAdapter.PlatformServices. Low
Medium Analyzers/MSTest.Analyzers/AssemblyFixtureProviderNotSupportedWithNativeAotAnalyzer.cs Analyzers/MSTest.Analyzers/AvoidUsingAssertsInAsyncVoidContextAnalyzer.cs 35 Extract Method Extract common analyzer logic into base classes or shared helper methods within MSTest.Analyzers project. Low
Medium Analyzers/MSTest.Analyzers/PreferAssertFailOverAlwaysFalseConditionsAnalyzer.cs Analyzers/MSTest.Analyzers/ReviewAlwaysTrueAssertConditionAnalyzer.cs 34 Extract Method Parameterize or extract common logic for assert condition analysis into shared helpers or base classes. Low
Medium Analyzers/MSTest.Analyzers/AssemblyFixtureProviderNotSupportedWithNativeAotAnalyzer.cs Analyzers/MSTest.Analyzers/AssertionArgsShouldBePassedInCorrectOrderAnalyzer.cs 30 Extract Method Consolidate common analyzer code to reduce duplication and improve maintainability. Low
Medium Analyzers/MSTest.Analyzers/CollectionAssertToAssertAnalyzer.cs Analyzers/MSTest.Analyzers/DoNotNegateBooleanAssertionAnalyzer.cs 30 Extract Method Extract shared logic for assertion analysis into common base or helper classes. Low
Medium Analyzers/MSTest.Analyzers/AssemblyFixtureProviderNotSupportedWithNativeAotAnalyzer.cs Analyzers/MSTest.Analyzers/AvoidAssertAreSameWithValueTypesAnalyzer.cs 29 Extract Method Refactor duplicated analyzer logic into shared helpers or base classes. Low
Medium Adapter/MSTestAdapter.PlatformServices/Execution/SynchronizationContextPreservingAsyncTaskMethodBuilder.cs (lines 17-50) Adapter/MSTestAdapter.PlatformServices/Execution/SynchronizationContextPreservingAsyncTaskMethodBuilder.cs (lines 63-96) 34 Intentional Code duplicated within the same file likely for different method overloads or partial class; leave as is. Low
Medium Platform/Microsoft.Testing.Platform/Messages/DataWithSessionUid.cs Platform/Microsoft.Testing.Platform/Messages/PropertyBagData.cs 31 Extract Base Class Extract common message data properties or behavior into a base class to reduce duplication. Low
Medium Platform/Microsoft.Testing.Platform/Messages/DataWithSessionUid.cs Platform/Microsoft.Testing.Platform/Messages/FileArtifacts.cs 28 Extract Base Class Consolidate shared message data into base class or shared helper to reduce duplication. Low
Medium Platform/Microsoft.Testing.Platform/Messages/DataWithSessionUid.cs Platform/Microsoft.Testing.Platform/Messages/TestNode.cs 28 Extract Base Class Same as above; unify common message data members in a base class. Low
Medium Platform/Microsoft.Testing.Platform/Messages/FileArtifacts.cs Platform/Microsoft.Testing.Platform/Messages/FileArtifacts.cs 29 Intentional Duplicate code in same file (different line ranges) likely intentional for overloads or partial methods. Low
Medium TestFramework/TestFramework/Assertions/Assert.ContainsSingle.Span.cs TestFramework/TestFramework/Assertions/Assert.ContainsSingle.cs 31 Template Method Parameterize or unify similar assertion methods to reduce duplication while preserving intent. Low
Low Adapter/MSTest.TestAdapter/Services/TestResultRecorderExtensions.cs Adapter/MSTestAdapter.PlatformServices/Execution/TestClassInfo.Initializer.cs 35 Intentional Different files and purposes; duplication likely coincidental or minimal; low priority for refactoring. Low
Low Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/WellKnownTypeProvider.cs Platform/Microsoft.Testing.Platform.MSBuild/Tasks/UnicodeCharacterUtilities.cs 34 Intentional Different projects and purposes; duplication likely coincidental or minimal; leave as is. Low
High Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Json.cs Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/JsonReflector.cs 54 Intentional These files are in the same folder and likely part of the same component; duplication may be intentional for isolation. Low
High Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Json.cs Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/JsonWriter.cs 54 Intentional Same as above; likely intentional duplication for component isolation or partial class usage. Low
High Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Json.cs Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/JsonReader.cs 45 Intentional Same as above; leave as is due to design or component isolation. Low
High Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/Json.cs Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/Json/Jsonite/JsonTypes.cs 44 Intentional Same as above; intentional duplication for component isolation or partial class design. Low

Summary

  • Total duplicates analyzed: 21 pairs
  • Classification counts:
    • Extract Method: 9
    • Extract Base Class: 3
    • Template Method: 1
    • Intentional: 8
  • High priority duplicates: 4 (mostly in run settings and JsonRpc Jsonite files)
  • Medium priority duplicates: 12
  • Low priority duplicates: 5

Top 3 recommended refactorings to tackle first

  1. RunSettings duplication between MSTestRunSettings.cs and RunSettingsPatcher.cs (51 and 33 lines)
    Consolidate duplicated run settings logic into a shared helper or common project to reduce maintenance overhead and avoid divergence between Adapter and VSTestBridge.

  2. Reflection helper duplication in MSTestAdapter.PlatformServices (32 lines)
    Extract reflection helper methods into a shared helper class to unify reflection operations and reduce duplicated code.

  3. Assertion analyzers duplication in MSTest.Analyzers (multiple 30+ line duplicates)
    Refactor common analyzer logic into base classes or shared helpers to improve maintainability and reduce duplicated code across analyzers.

The JsonRpc Jsonite duplicates appear intentional due to component design and should be left as is to avoid breaking changes.


Generated by dedup-analysis workflow using jscpd + GitHub Models (openai/gpt-4.1-mini)

Activity

  1. Evangelink commented on Jun 29, 2026

    @Evangelink
    Member

    Status update

    Several items from this duplication analysis have already been addressed by merged PRs:

    Remaining / not actioned (by design)

    • Jsonite JSON-parser duplicates (Json.cs vs JsonReader/JsonWriter/JsonReflector/JsonTypes, the 4 high-priority rows) — this is vendored third-party code that the repo does not hand-edit, so it is intentionally left as-is.
    • Message DTO "extract base class" rows (DataWithSessionUid, PropertyBagData, FileArtifacts, TestNode, TestNodeUpdateMessage, …) — these are public/serialized message types where a shared base class would risk the wire/serialization contract; treated as intentional unless a concrete refactor is scoped.
    • Smaller intra-file "extract method" rows are low priority.

    Leaving this umbrella issue open to track any of the remaining low/medium items the team chooses to pick up.

  2. added
    type/tech-debt
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/tech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions