Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 58 additions & 27 deletions TUnit.Analyzers/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,82 @@

### New Rules

#### Test Method and Structure Rules

Check warning on line 5 in TUnit.Analyzers/AnalyzerReleases.Shipped.md

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Analyzer release file 'AnalyzerReleases.Shipped.md' has a missing or invalid release header '#### Test Method and Structure Rules' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)

Check warning on line 5 in TUnit.Analyzers/AnalyzerReleases.Shipped.md

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Analyzer release file 'AnalyzerReleases.Shipped.md' has a missing or invalid release header '#### Test Method and Structure Rules' (https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md)
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0001 | Usage | Error | Test argument types don't match method parameters
TUnit0002 | Usage | Error | No data provided for test
TUnit0013 | Usage | Error | Test has more arguments than method parameters
TUnit0014 | Usage | Warning | Public test method missing [Test] attribute - add attribute or make method private/protected
TUnit0019 | Usage | Error | Test method missing [Test] attribute
TUnit0048 | Usage | Error | Test methods in non-static classes must not be static
TUnit0051 | Usage | Error | Test class must be public

#### Data Source and Parameter Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0004 | Usage | Error | Data source method not found
TUnit0005 | Usage | Warning | Nullable parameter has non-nullable argument - consider making the argument nullable
TUnit0007 | Usage | Error | Data source method must be static
TUnit0008 | Usage | Error | Data source method must be public
TUnit0009 | Usage | Error | Data source method cannot be abstract
TUnit0010 | Usage | Error | Data source method must be parameterless
TUnit0011 | Usage | Error | Data source method must return data (IEnumerable or Task<IEnumerable>)
TUnit0013 | Usage | Error | Test has more arguments than method parameters
TUnit0014 | Usage | Warning | Public test method missing [Test] attribute - add attribute or make method private/protected
TUnit0015 | Usage | Error | Methods with [Timeout] must have a CancellationToken parameter
TUnit0016 | Usage | Error | Hook methods must not be static
TUnit0017 | Usage | Error | [Explicit] attribute cannot be on both method and class - choose one location
TUnit0018 | Usage | Warning | Test methods should not assign instance fields/properties - consider using static fields or [NotInParallel]
TUnit0019 | Usage | Error | Test method missing [Test] attribute
TUnit0023 | Usage | Warning | Disposable fields/properties should be disposed in cleanup methods ([After(Test)] or [After(Class)])
TUnit0027 | Usage | Error | Hook method has incorrect parameters - check expected parameter types for this hook
TUnit0028 | Usage | Error | Do not override TUnit's AttributeUsage settings
TUnit0029 | Usage | Error | Duplicate attribute where only one is allowed
TUnit0030 | Usage | Warning | Test class doesn't inherit base class tests - add [InheritsTests] to include them
TUnit0031 | Usage | Error | Async void methods not allowed - return Task instead
TUnit0032 | Usage | Error | [DependsOn] and [NotInParallel] attributes conflict - tests with dependencies must support parallel execution
TUnit0033 | Usage | Error | Circular or conflicting test dependencies detected
TUnit0034 | Usage | Error | Do not declare a Main method in test projects - TUnit provides its own entry point
TUnit0038 | Usage | Error | Property with data attribute must have a data source attribute
TUnit0039 | Usage | Error | Test hook methods require single TestContext parameter
TUnit0040 | Usage | Error | Class hook methods require single ClassHookContext parameter
TUnit0041 | Usage | Error | Assembly hook methods require single AssemblyHookContext parameter
TUnit0042 | Usage | Warning | Global hooks should be in separate classes from tests for clarity
TUnit0043 | Usage | Error | Properties with data attributes must use 'required' keyword
TUnit0044 | Usage | Error | Properties with data attributes must have a setter
TUnit0045 | Usage | Error | Property has multiple data source attributes - use only one
TUnit0046 | Usage | Warning | Data source should return Func<T> for lazy evaluation instead of T
TUnit0047 | Usage | Warning | AsyncLocal values from BeforeTest hooks require context.AddAsyncLocalValue() to flow to tests
TUnit0048 | Usage | Error | Test methods in non-static classes must not be static
TUnit0049 | Usage | Error | [Matrix] parameters require [MatrixDataSource] attribute on the test method
TUnit0050 | Usage | Error | Too many test arguments provided
TUnit0051 | Usage | Error | Test class must be public
TUnit0055 | Usage | Warning | Do not overwrite Console.Out/Error - it breaks TUnit logging
TUnit0056 | Usage | Error | Instance data source methods must use [InstanceMethodDataSource] attribute
TUnit0058 | Usage | Error | Generic test methods require [GenerateGenericTest] for AOT compatibility
TUnit0059 | Usage | Error | Dynamic data sources using reflection are not AOT-compatible - use static sources
TUnit0060 | Usage | Error | Open generic types are not AOT-compatible - specify concrete type arguments

#### Hook and Lifecycle Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0016 | Usage | Error | Hook methods must not be static
TUnit0027 | Usage | Error | Hook method has incorrect parameters - check expected parameter types for this hook
TUnit0039 | Usage | Error | Test hook methods require single TestContext parameter
TUnit0040 | Usage | Error | Class hook methods require single ClassHookContext parameter
TUnit0041 | Usage | Error | Assembly hook methods require single AssemblyHookContext parameter
TUnit0042 | Usage | Warning | Global hooks should be in separate classes from tests for clarity
TUnit0047 | Usage | Warning | AsyncLocal values from BeforeTest hooks require context.AddAsyncLocalValue() to flow to tests
TUnit0057 | Usage | Info | Hook context parameter available - consider adding for additional context information
TUnit0058 | Usage | Error | Hook method has unknown parameters - check expected parameter types for this hook

#### Attribute and Metadata Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0017 | Usage | Error | [Explicit] attribute cannot be on both method and class - choose one location
TUnit0028 | Usage | Error | Do not override TUnit's AttributeUsage settings
TUnit0029 | Usage | Error | Duplicate attribute where only one is allowed
TUnit0030 | Usage | Warning | Test class doesn't inherit base class tests - add [InheritsTests] to include them
TUnit0032 | Usage | Error | [DependsOn] and [NotInParallel] attributes conflict - tests with dependencies must support parallel execution
TUnit0033 | Usage | Error | Circular or conflicting test dependencies detected

#### Async and Execution Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0015 | Usage | Error | Methods with [Timeout] must have a CancellationToken parameter
TUnit0031 | Usage | Error | Async void methods not allowed - return Task instead
TUnit0200 | Usage | Warning | Avoid blocking on async code (.Result, .GetAwaiter().GetResult()) - use await instead

#### AOT Compatibility Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0300 | Usage | Warning | Generic types may not be AOT-compatible - ensure all combinations are known at compile time
TUnit0301 | Usage | Warning | Tuple usage may not be AOT-compatible - consider using concrete types
TUnit0302 | Usage | Warning | Custom conversion operators may not be AOT-compatible - use explicit casting

#### Best Practices and Warnings
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUnit0018 | Usage | Warning | Test methods should not assign instance fields/properties - consider using static fields or [NotInParallel]
TUnit0023 | Usage | Warning | Disposable fields/properties should be disposed in cleanup methods ([After(Test)] or [After(Class)])
TUnit0034 | Usage | Error | Do not declare a Main method in test projects - TUnit provides its own entry point
TUnit0055 | Usage | Warning | Do not overwrite Console.Out/Error - it breaks TUnit logging

#### Migration and Legacy Support
Rule ID | Category | Severity | Notes
--------|----------|----------|------------------------------------------------
TUXU0001 | Usage | Info | XUnit code can be migrated to TUnit
154 changes: 29 additions & 125 deletions TUnit.Analyzers/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,51 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TUnit0001Description" xml:space="preserve">
<value>The arguments for this test don't match the method argument types.</value>
<value>Test data argument types don't match the method parameter types. Ensure the types specified in [Arguments] attributes match the method signature.</value>
</data>
<data name="TUnit0001MessageFormat" xml:space="preserve">
<value>Attribute argument types '{0}' don't match method parameter types '{1}'</value>
</data>
<data name="TUnit0001Title" xml:space="preserve">
<value>Invalid Data for Tests</value>
<value>Test argument types don't match method parameters</value>
</data>
<data name="TUnit0002Description" xml:space="preserve">
<value>No data provided for test.</value>
<value>Test method requires data but none was provided. Add [Arguments] or data source attributes to provide test data.</value>
</data>
<data name="TUnit0002MessageFormat" xml:space="preserve">
<value>No data provided for test</value>
</data>
<data name="TUnit0002Title" xml:space="preserve">
<value>No data provided for test</value>
</data>
<data name="TUnit0003Description" xml:space="preserve">
<value>No data provided for test.</value>
</data>
<data name="TUnit0003MessageFormat" xml:space="preserve">
<value>No data provided for test</value>
</data>
<data name="TUnit0003Title" xml:space="preserve">
<value>No data provided for test</value>
</data>

<data name="TUnit0004Description" xml:space="preserve">
<value>No method found.</value>
<value>Data source method not found. Ensure the method name is correct, accessible, and follows the required signature.</value>
</data>
<data name="TUnit0004MessageFormat" xml:space="preserve">
<value>No method found</value>
<value>Data source method not found</value>
</data>
<data name="TUnit0004Title" xml:space="preserve">
<value>No method found</value>
<value>Data source method not found</value>
</data>
<data name="TUnit0005Description" xml:space="preserve">
<value>The parameter is not defined as nullable.</value>
<value>Nullable parameter has non-nullable argument. Consider making the argument nullable or the parameter non-nullable to match.</value>
</data>
<data name="TUnit0005MessageFormat" xml:space="preserve">
<value>The parameter '{0}' is not defined as nullable</value>
</data>
<data name="TUnit0005Title" xml:space="preserve">
<value>The parameter is not defined as nullable</value>
</data>
<data name="TUnit0006Description" xml:space="preserve">
<value>Data source doesn't match method argument type.</value>
</data>
<data name="TUnit0006MessageFormat" xml:space="preserve">
<value>The data source type `{0}` doesn't match the parameter type `{1}`</value>
</data>
<data name="TUnit0006Title" xml:space="preserve">
<value>Data source doesn't match method argument type</value>
<value>Nullable parameter has non-nullable argument</value>
</data>

<data name="TUnit0007Description" xml:space="preserve">
<value>Method must be static.</value>
<value>Data source method must be static. Change the method to static or use [InstanceMethodDataSource] for instance methods.</value>
</data>
<data name="TUnit0007MessageFormat" xml:space="preserve">
<value>Method must be static</value>
<value>Data source method must be static</value>
</data>
<data name="TUnit0007Title" xml:space="preserve">
<value>Method must be static</value>
<value>Data source method must be static</value>
</data>
<data name="TUnit0008Description" xml:space="preserve">
<value>Method must be public.</value>
Expand Down Expand Up @@ -109,23 +93,15 @@
<value>Method should be parameterless</value>
</data>
<data name="TUnit0011Description" xml:space="preserve">
<value>Method returns void.</value>
<value>Data source method must return data. Method should return IEnumerable or Task&lt;IEnumerable&gt; to provide test data.</value>
</data>
<data name="TUnit0011MessageFormat" xml:space="preserve">
<value>Method returns void</value>
<value>Data source method must return data (IEnumerable or Task&lt;IEnumerable&gt;)</value>
</data>
<data name="TUnit0011Title" xml:space="preserve">
<value>Method returns void</value>
</data>
<data name="TUnit0012Description" xml:space="preserve">
<value>There is no argument for the data source.</value>
</data>
<data name="TUnit0012MessageFormat" xml:space="preserve">
<value>There is no argument for the data source</value>
</data>
<data name="TUnit0012Title" xml:space="preserve">
<value>There is no argument for the data source</value>
<value>Data source method must return data</value>
</data>

<data name="TUnit0013Description" xml:space="preserve">
<value>A data source method must only have 1 matching parameter.</value>
</data>
Expand All @@ -136,13 +112,13 @@
<value>A data source method must only have 1 matching parameter</value>
</data>
<data name="TUnit0014Description" xml:space="preserve">
<value>Method should have a `Test` attribute or be made `private` or `protected`.</value>
<value>Public method in test class should have [Test] attribute or be made private/protected. Test methods must be explicitly marked with [Test].</value>
</data>
<data name="TUnit0014MessageFormat" xml:space="preserve">
<value>Method should have a `Test` attribute or be made `private` or `protected`</value>
<value>Public method missing [Test] attribute - add attribute or make method private/protected</value>
</data>
<data name="TUnit0014Title" xml:space="preserve">
<value>Method should have a `Test` attribute or be made `private` or `protected`</value>
<value>Public method missing [Test] attribute</value>
</data>
<data name="TUnit0015Description" xml:space="preserve">
<value>Missing TimeoutAttribute cancellation token parameter.</value>
Expand Down Expand Up @@ -189,33 +165,9 @@
<data name="TUnit0019Title" xml:space="preserve">
<value>Missing `Test` Attribute</value>
</data>
<data name="TUnit0020Description" xml:space="preserve">
<value>`DataDrivenTest` must have an `Arguments` attribute, or vice versa.</value>
</data>
<data name="TUnit0020MessageFormat" xml:space="preserve">
<value>`DataDrivenTest` must have an `Arguments` attribute, or vice versa.</value>
</data>
<data name="TUnit0020Title" xml:space="preserve">
<value>`DataDrivenTest` must be paired with `Arguments` attributes.</value>
</data>
<data name="TUnit0021Description" xml:space="preserve">
<value>`DataSourceDrivenTest` must have a `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attribute, or vice versa.</value>
</data>
<data name="TUnit0021MessageFormat" xml:space="preserve">
<value>`DataSourceDrivenTest` must have a `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attribute, or vice versa.</value>
</data>
<data name="TUnit0021Title" xml:space="preserve">
<value>`DataSourceDrivenTest` must be paired with either `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attributes.</value>
</data>
<data name="TUnit0022Description" xml:space="preserve">
<value>`MatrixTest` parameters must have `Matrix` attributes on them, or vice versa.</value>
</data>
<data name="TUnit0022MessageFormat" xml:space="preserve">
<value>`MatrixTest` parameters must have `Matrix` attributes on them, or vice versa.</value>
</data>
<data name="TUnit0022Title" xml:space="preserve">
<value>`MatrixTest` must be paired with `Matrix` attributes.</value>
</data>



<data name="TUnit0023Description" xml:space="preserve">
<value>Member should be disposed within a clean up method</value>
</data>
Expand All @@ -225,33 +177,9 @@
<data name="TUnit0023Title" xml:space="preserve">
<value>Member should be disposed within a clean up method</value>
</data>
<data name="TUnit0024Description" xml:space="preserve">
<value>Test methods should use `TUnit.Core.CategoryAttribute` instead of `System.ComponentModel.CategoryAttribute`</value>
</data>
<data name="TUnit0024MessageFormat" xml:space="preserve">
<value>Test methods should use `TUnit.Core.CategoryAttribute` instead of `System.ComponentModel.CategoryAttribute`</value>
</data>
<data name="TUnit0024Title" xml:space="preserve">
<value>Wrong `Category` attribute</value>
</data>
<data name="TUnit0025Description" xml:space="preserve">
<value>The number of arguments doesn't match the number of parameters</value>
</data>
<data name="TUnit0025MessageFormat" xml:space="preserve">
<value>The number of arguments `{0}` doesn't match the number of parameters `{1}`</value>
</data>
<data name="TUnit0025Title" xml:space="preserve">
<value>Invalid arguments count</value>
</data>
<data name="TUnit0026Description" xml:space="preserve">
<value>Not an IEnumerable</value>
</data>
<data name="TUnit0026MessageFormat" xml:space="preserve">
<value>`{0}` should be an IEnumerable</value>
</data>
<data name="TUnit0026Title" xml:space="preserve">
<value>Not an IEnumerable</value>
</data>



<data name="TUnit0027Description" xml:space="preserve">
<value>The specified parameters aren't allowed for this method.</value>
</data>
Expand Down Expand Up @@ -324,33 +252,9 @@
<data name="TUnit0034Title" xml:space="preserve">
<value>Do not declare a main method</value>
</data>
<data name="TUnit0035Description" xml:space="preserve">
<value>ClassDataSource expects a matching parameter.</value>
</data>
<data name="TUnit0035MessageFormat" xml:space="preserve">
<value>ClassDataSource expects a matching parameter</value>
</data>
<data name="TUnit0035Title" xml:space="preserve">
<value>ClassDataSource expects a matching parameter</value>
</data>
<data name="TUnit0036Description" xml:space="preserve">
<value>Type must be public..</value>
</data>
<data name="TUnit0036MessageFormat" xml:space="preserve">
<value>Type must be public</value>
</data>
<data name="TUnit0036Title" xml:space="preserve">
<value>Type must be public</value>
</data>
<data name="TUnit0037Description" xml:space="preserve">
<value>Constructor should be parameterless.</value>
</data>
<data name="TUnit0037MessageFormat" xml:space="preserve">
<value>Constructor should be parameterless</value>
</data>
<data name="TUnit0037Title" xml:space="preserve">
<value>Constructor should be parameterless</value>
</data>



<data name="TUnit0038Description" xml:space="preserve">
<value>No data source provided.</value>
</data>
Expand Down
Loading
Loading