Skip to content

perf: AbstractTestClassWithDataSourcesAnalyzer scans all types globally #4864

@thomhurst

Description

@thomhurst

Description

File: TUnit.Analyzers/AbstractTestClassWithDataSourcesAnalyzer.cs (Lines 107, 153-175)

var allTypes = GetAllNamedTypes(context.Compilation.GlobalNamespace);

This recursively walks every type in the entire compilation (including all referenced assemblies) every time an abstract type is analyzed. This is O(n) per abstract test class.

Additionally, data source detection (lines 63-79) uses fragile string-contains checks:

if (typeName.Contains("DataSource") || typeName == "ArgumentsAttribute")

Custom data sources without "DataSource" in the name will be missed.

Suggested Fix

  • Cache the type hierarchy or restrict search to the current assembly
  • Rely on the interface check (IDataSourceAttribute) instead of string-based matching

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions