diff --git a/TUnit.Analyzers/AnalyzerReleases.Shipped.md b/TUnit.Analyzers/AnalyzerReleases.Shipped.md index 7bfa50ded8..6e63b6661b 100644 --- a/TUnit.Analyzers/AnalyzerReleases.Shipped.md +++ b/TUnit.Analyzers/AnalyzerReleases.Shipped.md @@ -2,10 +2,21 @@ ### New Rules +#### Test Method and Structure Rules 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 +TUnit0052 | Usage | Warning | Multiple constructors found without [TestConstructor] attribute + +#### 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 @@ -13,39 +24,60 @@ 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) -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 +TUnit0038 | Usage | Error | Property with data attribute must have a data source attribute +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 for lazy evaluation instead of T +TUnit0049 | Usage | Error | [Matrix] parameters require [MatrixDataSource] attribute on the test method +TUnit0050 | Usage | Error | Too many test arguments provided +TUnit0056 | Usage | Error | Instance data source methods must use [InstanceMethodDataSource] attribute + +#### Hook and Lifecycle Rules +Rule ID | Category | Severity | Notes +--------|----------|----------|------------------------------------------------ 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 +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 -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 + +#### 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 + +#### 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 -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 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 + +#### Migration and Legacy Support +Rule ID | Category | Severity | Notes +--------|----------|----------|------------------------------------------------ TUXU0001 | Usage | Info | XUnit code can be migrated to TUnit \ No newline at end of file diff --git a/TUnit.Analyzers/Resources.resx b/TUnit.Analyzers/Resources.resx index 65fa164775..4afbc03512 100644 --- a/TUnit.Analyzers/Resources.resx +++ b/TUnit.Analyzers/Resources.resx @@ -19,16 +19,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - The arguments for this test don't match the method argument types. + Test data argument types don't match the method parameter types. Ensure the types specified in [Arguments] attributes match the method signature. Attribute argument types '{0}' don't match method parameter types '{1}' - Invalid Data for Tests + Test argument types don't match method parameters - No data provided for test. + Test method requires data but none was provided. Add [Arguments] or data source attributes to provide test data. No data provided for test @@ -36,50 +36,34 @@ No data provided for test - - No data provided for test. - - - No data provided for test - - - No data provided for test - + - No method found. + Data source method not found. Ensure the method name is correct, accessible, and follows the required signature. - No method found + Data source method not found - No method found + Data source method not found - The parameter is not defined as nullable. + Nullable parameter has non-nullable argument. Consider making the argument nullable or the parameter non-nullable to match. The parameter '{0}' is not defined as nullable - The parameter is not defined as nullable - - - Data source doesn't match method argument type. - - - The data source type `{0}` doesn't match the parameter type `{1}` - - - Data source doesn't match method argument type + Nullable parameter has non-nullable argument + - Method must be static. + Data source method must be static. Change the method to static or use [InstanceMethodDataSource] for instance methods. - Method must be static + Data source method must be static - Method must be static + Data source method must be static Method must be public. @@ -109,23 +93,15 @@ Method should be parameterless - Method returns void. + Data source method must return data. Method should return IEnumerable or Task<IEnumerable> to provide test data. - Method returns void + Data source method must return data (IEnumerable or Task<IEnumerable>) - Method returns void - - - There is no argument for the data source. - - - There is no argument for the data source - - - There is no argument for the data source + Data source method must return data + A data source method must only have 1 matching parameter. @@ -136,13 +112,13 @@ A data source method must only have 1 matching parameter - Method should have a `Test` attribute or be made `private` or `protected`. + Public method in test class should have [Test] attribute or be made private/protected. Test methods must be explicitly marked with [Test]. - Method should have a `Test` attribute or be made `private` or `protected` + Public method missing [Test] attribute - add attribute or make method private/protected - Method should have a `Test` attribute or be made `private` or `protected` + Public method missing [Test] attribute Missing TimeoutAttribute cancellation token parameter. @@ -189,33 +165,9 @@ Missing `Test` Attribute - - `DataDrivenTest` must have an `Arguments` attribute, or vice versa. - - - `DataDrivenTest` must have an `Arguments` attribute, or vice versa. - - - `DataDrivenTest` must be paired with `Arguments` attributes. - - - `DataSourceDrivenTest` must have a `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attribute, or vice versa. - - - `DataSourceDrivenTest` must have a `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attribute, or vice versa. - - - `DataSourceDrivenTest` must be paired with either `MethodDataSource`, `MethodDataSource` or `ClassDataSource` attributes. - - - `MatrixTest` parameters must have `Matrix` attributes on them, or vice versa. - - - `MatrixTest` parameters must have `Matrix` attributes on them, or vice versa. - - - `MatrixTest` must be paired with `Matrix` attributes. - + + + Member should be disposed within a clean up method @@ -225,33 +177,9 @@ Member should be disposed within a clean up method - - Test methods should use `TUnit.Core.CategoryAttribute` instead of `System.ComponentModel.CategoryAttribute` - - - Test methods should use `TUnit.Core.CategoryAttribute` instead of `System.ComponentModel.CategoryAttribute` - - - Wrong `Category` attribute - - - The number of arguments doesn't match the number of parameters - - - The number of arguments `{0}` doesn't match the number of parameters `{1}` - - - Invalid arguments count - - - Not an IEnumerable - - - `{0}` should be an IEnumerable - - - Not an IEnumerable - + + + The specified parameters aren't allowed for this method. @@ -324,33 +252,9 @@ Do not declare a main method - - ClassDataSource expects a matching parameter. - - - ClassDataSource expects a matching parameter - - - ClassDataSource expects a matching parameter - - - Type must be public.. - - - Type must be public - - - Type must be public - - - Constructor should be parameterless. - - - Constructor should be parameterless - - - Constructor should be parameterless - + + + No data source provided. diff --git a/TUnit.Assertions.Analyzers/AnalyzerReleases.Shipped.md b/TUnit.Assertions.Analyzers/AnalyzerReleases.Shipped.md index fcae4100b7..0d347044ac 100644 --- a/TUnit.Assertions.Analyzers/AnalyzerReleases.Shipped.md +++ b/TUnit.Assertions.Analyzers/AnalyzerReleases.Shipped.md @@ -2,14 +2,23 @@ ### New Rules +#### Assertion Usage Rules Rule ID | Category | Severity | Notes --------|----------|----------|------------------------------------------------ TUnitAssertions0001 | Usage | Warning | Don't mix 'Or' & 'And' operators in assertions - use parentheses to clarify precedence TUnitAssertions0002 | Usage | Error | Assert statements must be awaited - all TUnit assertions return Task -TUnitAssertions0003 | Usage | Warning | Don't provide CallerArgumentExpression parameter values - let the compiler handle it TUnitAssertions0004 | Usage | Error | Assert.Multiple requires 'using' statement for proper scoping + +#### Assertion Best Practices +Rule ID | Category | Severity | Notes +--------|----------|----------|------------------------------------------------ +TUnitAssertions0003 | Usage | Warning | Don't provide CallerArgumentExpression parameter values - let the compiler handle it TUnitAssertions0005 | Usage | Warning | Assert.That() should not be used with constant values - the assertion will always pass or fail TUnitAssertions0006 | Usage | Error | Use .IsEqualTo() instead of calling object.Equals() for better assertion messages TUnitAssertions0007 | Usage | Error | Cast dynamic values to 'object?' when using Assert.That() for proper type inference TUnitAssertions0008 | Usage | Error | Await ValueTask before passing to Assert.That() - use 'await' keyword + +#### Migration Support +Rule ID | Category | Severity | Notes +--------|----------|----------|------------------------------------------------ TUnitAssertions0009 | Usage | Info | XUnit assertion can be migrated to TUnit assertion syntax \ No newline at end of file diff --git a/TUnit.Assertions.Analyzers/Resources.resx b/TUnit.Assertions.Analyzers/Resources.resx index 6cd7bc116b..80e6833fe2 100644 --- a/TUnit.Assertions.Analyzers/Resources.resx +++ b/TUnit.Assertions.Analyzers/Resources.resx @@ -19,37 +19,37 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Don't mix 'Or' & 'And' operators in assertions. + Mixing 'Or' and 'And' operators in assertions can create ambiguous logic. Use parentheses to clarify operator precedence and make the assertion intent clear. - Don't mix 'Or' & 'And' operators in assertions + Don't mix 'Or' & 'And' operators in assertions - use parentheses to clarify precedence - Don't mix 'Or' & 'And' operators in assertions + Mixed 'Or' and 'And' operators in assertion Don't mix 'Or' & 'And' operators in assertionsThe title of the code fix. - Assert statements must be awaited. + All TUnit assertions return Task and must be awaited. Add 'await' before the assertion statement. - Assert statements must be awaited + Assert statements must be awaited - all TUnit assertions return Task - Assert statements must be awaited + Assert statement not awaited Assert statements must be awaitedThe title of the code fix. - Do not populate this argument. The compiler will do this. + CallerArgumentExpression parameters are automatically populated by the compiler. Remove manually provided values to allow proper expression capture. - Do not populate this argument. The compiler will do this + Don't provide CallerArgumentExpression parameter values - let the compiler handle it - Compiler argument populated + Manual CallerArgumentExpression parameter provided Assert.Multiple needs a `using` before it.