Instance method data-source diagnostic depends on constructor declaration order
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #7502 by @thomhurst — merged
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The bug is in canBeInstanceMethod in src/TUnit.Analyzers/TestDataAnalyzer.cs near line 512, which checks only InstanceConstructors.First(). Compare it with the preceding instance-method check, which searches all constructors, and see how the diagnostic is reported. Done means a parameterless constructor is found whichever order the constructors are declared, with a regression test covering both orders.
Written by the indexing model from the issue text.
Description
An instance method data-source diagnostic depends on constructor declaration order. TestDataAnalyzer checks only the first constructor when deciding whether a test class has a parameterless constructor, so it can report that a data-source method must be static even when a parameterless constructor exists.
Reproduction
Declare a test class with a parameterized constructor first and a public parameterless constructor second. On a test method, use the explicit-type overload [MethodDataSource(typeof(Tests), nameof(Data))] with a public instance Data method returning IEnumerable<int>. Reverse the constructor order and compare diagnostics.
Expected and actual
Parameterless-constructor availability should not depend on declaration order. canBeInstanceMethod in src/TUnit.Analyzers/TestDataAnalyzer.cs:512 uses InstanceConstructors.First(), whereas the preceding instance-method check searches all constructors. Check all applicable constructors and add a regression for both declaration orders.
Environment
Confirmed by source inspection on main commit a412ddd5a5 and PR #7449. This is separate from selecting [TestConstructor] for class-level data rows: instance-source creation can use a parameterless constructor. Runtime reproduction has not yet been run. Related historical issue #1821 concerns the absence of a parameterless constructor rather than declaration order.
- Dominant language
- C#
- Stars
- 4k
- Forks
- 139
- Avg merge
- 7h 54m
- Merged PRs (30d)
- 359
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from thomhurst/TUnit
-
bug P3
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
thomhurst/TUnit#7585 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation P3
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
thomhurst/TUnit#7444 · 1 comment ·
Maintainers usually reply within 1 day
-
Mock and core generator test restores report vulnerable System.Security.Cryptography.Pkcs versionsPossibly taken A pull request linked to this issue is open or already merged. Opendependencies P2
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
thomhurst/TUnit#7412 · 8 comments ·
Maintainers usually reply within 1 day
-
enhancement P3 performance
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
thomhurst/TUnit#7380 · 2 comments ·
Maintainers usually reply within 1 day
-
bug github_actions P2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
thomhurst/TUnit#7229 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Add All ContributorsOpenenhancement ready-for-human
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
fboucher/2d6-dungeon-app#288 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Unity-Technologies/unity-agent-plugin#118 ·
Maintainers usually reply within 1 day
-
The Recommended preset turns on Import Uno DSP, which only works with the Material themePossibly taken @agneszitte claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
unoplatform/uno.templates#2388 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
eyalgolan/statecraft-israel#2732 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
StratumServer/Optimum#198 ·
Maintainers usually reply within 1 day