TestDataAnalyzer: detect Func<T> by symbol instead of display-string prefix

Open Beginner friendly
#7,380 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
testing

Research direction

The three display-string checks are at src/TUnit.Analyzers/TestDataAnalyzer.cs lines 548, 569 and 870; line 870 may live on the branch from #7347 rather than main. Look at how TestDataRow1 is already compared by symbol in the same file and mirror that pattern. Done means all three sites compare OriginalDefinition against a System.Func1 symbol resolved once per compilation, and tests/TUnit.Analyzers.Tests still pass.

Written by the indexing model from the issue text.

Description

enhancement P3 performance

TestDataAnalyzer detects Func<T> by calling ToDisplayString().StartsWith("System.Func<", StringComparison.Ordinal). This allocates a display string during analysis and relies on formatting instead of symbol identity.

Current code

Following merged PR #7347 (#7227), the three checks are:

  • Two property-injection checks in src/TUnit.Analyzers/TestDataAnalyzer.cs, using funcType and funcTypeForError.
  • TryUnwrapFunc in the same file, called while peeling the supported data-row wrappers.

Both automated reviewers raised this as non-blocking on #7347 (review comment). That prerequisite has merged; this issue is available for implementation.

Acceptance criteria

  • Resolve System.Func`1 once per compilation with Compilation.GetTypeByMetadataName("System.Func`1").
  • Compare OriginalDefinition with SymbolEqualityComparer.Default in all three checks, as the analyzer already does for TestDataRow<T>.
  • Preserve the existing wrapper-peeling order and property-injection behavior.
  • Add analyzer cases for Func<TestDataRow<(int, int)>> and TestDataRow<Func<(int, int)>> against an (int a, int b) test signature. These are regression coverage for the existing tuple expansion after wrapper peeling; there is no known defect in that ordering.
  • Run the relevant TUnit.Analyzers.Tests coverage.
Dominant language
C#
Stars
4k
Forks
139
Avg merge
9h 6m
Merged PRs (30d)
282

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from thomhurst/TUnit

All issues in thomhurst/TUnit

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.