Skip to content

Commit 6b07ac6

Browse files
Copilotthomhurst
andauthored
Clarify TUnit0046 diagnostic message for data source return types (#3843)
* Initial plan * Update TUnit0046 analyzer message to be clearer Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com> * Update documentation for TUnit0046 to match new message Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
1 parent dbe74b0 commit 6b07ac6

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

TUnit.Analyzers/AnalyzerReleases.Shipped.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TUnit0038 | Usage | Error | Property with data attribute must have a data source
2828
TUnit0043 | Usage | Error | Properties with data attributes must use 'required' keyword
2929
TUnit0044 | Usage | Error | Properties with data attributes must have a setter
3030
TUnit0045 | Usage | Error | Property has multiple data source attributes - use only one
31-
TUnit0046 | Usage | Warning | Data source should return Func<T> for lazy evaluation instead of T
31+
TUnit0046 | Usage | Warning | Data source should return Func<T> for reference types to ensure test isolation
3232
TUnit0049 | Usage | Error | [Matrix] parameters require [MatrixDataSource] attribute on the test method
3333
TUnit0050 | Usage | Error | Too many test arguments provided
3434
TUnit0056 | Usage | Error | Instance data source methods must use [InstanceMethodDataSource] attribute

TUnit.Analyzers/Resources.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@
328328
<value>Too many data attributes</value>
329329
</data>
330330
<data name="TUnit0046Description" xml:space="preserve">
331-
<value>Return a `Func&lt;T&gt;` rather than a `&lt;T&gt;`.</value>
331+
<value>When a data source method provides reference types (other than string) as test parameters, it should return Func&lt;T&gt; to defer object creation until the test runs. This prevents shared state between tests and ensures proper test isolation.</value>
332332
</data>
333333
<data name="TUnit0046MessageFormat" xml:space="preserve">
334-
<value>Return a `Func&lt;T&gt;` rather than a `&lt;T&gt;`.</value>
334+
<value>Data source method should return Func&lt;T&gt; for reference type parameters (other than string) to ensure proper test isolation</value>
335335
</data>
336336
<data name="TUnit0046Title" xml:space="preserve">
337-
<value>Return a `Func&lt;T&gt;` rather than a `&lt;T&gt;`</value>
337+
<value>Data source should return Func&lt;T&gt; for reference types</value>
338338
</data>
339339
<data name="TUnit0047Description" xml:space="preserve">
340340
<value>For AsyncLocal values set in before hooks, you must call `context.AddAsyncLocalValues` to access them within tests.</value>

0 commit comments

Comments
 (0)