diff --git a/TUnit.Analyzers.Tests/PublicMethodMissingTestAttributeAnalyzerTests.cs b/TUnit.Analyzers.Tests/PublicMethodMissingTestAttributeAnalyzerTests.cs index ad1b42724e..f09738aa61 100644 --- a/TUnit.Analyzers.Tests/PublicMethodMissingTestAttributeAnalyzerTests.cs +++ b/TUnit.Analyzers.Tests/PublicMethodMissingTestAttributeAnalyzerTests.cs @@ -143,7 +143,7 @@ public class MyClass : IAsyncDisposable public void MyTest() { } - + public ValueTask DisposeAsync() { return ValueTask.CompletedTask; @@ -152,4 +152,104 @@ public ValueTask DisposeAsync() """ ); } + + [Test] + public async Task Property_Getter_Setter_No_Error() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using TUnit.Core; + + public class MyClass + { + [Test] + public void MyTest() + { + } + + public string? Name { get; set; } + + public int Age + { + get { return 0; } + set { } + } + } + """ + ); + } + + [Test] + public async Task Event_Accessors_No_Error() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using TUnit.Core; + + public class MyClass + { + [Test] + public void MyTest() + { + } + + public event EventHandler MyEvent + { + add { } + remove { } + } + } + """ + ); + } + + [Test] + public async Task Override_Method_No_Error() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using TUnit.Core; + + public class MyClass + { + [Test] + public void MyTest() + { + } + + public override string ToString() + { + return "test"; + } + } + """ + ); + } + + [Test] + public async Task Static_Method_No_Error() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using TUnit.Core; + + public class MyClass + { + [Test] + public void MyTest() + { + } + + public static void StaticHelper() + { + } + } + """ + ); + } } diff --git a/TUnit.Analyzers/PublicMethodMissingTestAttributeAnalyzer.cs b/TUnit.Analyzers/PublicMethodMissingTestAttributeAnalyzer.cs index 05838c678b..6fe17e4054 100644 --- a/TUnit.Analyzers/PublicMethodMissingTestAttributeAnalyzer.cs +++ b/TUnit.Analyzers/PublicMethodMissingTestAttributeAnalyzer.cs @@ -32,6 +32,9 @@ private void AnalyzeSymbol(SymbolAnalysisContext context) return; } + // MethodKind.Ordinary excludes property accessors (PropertyGet/PropertySet), + // event accessors (EventAdd/EventRemove), constructors, destructors, operators, + // and other compiler-generated method kinds. foreach (var method in methods .Where(x => x.MethodKind == MethodKind.Ordinary) .Where(x => !x.IsAbstract)