Skip to content

[Bug]: TUnit0059 false positive when there are no subclasses in the same assembly #4607

@aradalvand

Description

@aradalvand

Description

I have a "testing library" on top of TUnit that provides a bunch of abstract test classes that users of the library could then extend and use. Naturally, the abstract test classes I define are expected to be subclassed by consuming assemblies, rather than by other classes in the same assembly. This results in the TUnit0059 warning, stating "Abstract test class 'KitSerializationRoundtripTests' has test methods with data sources. Add [InheritsTests] on a concrete class to execute these tests."

But this isn't applicable when there are no actual subclasses in the same assembly to miss [InheritsTests] annotations in the first place. Consider incorporating this understanding into the analyzer.

Minimal repro:

public abstract class SomeTest
{
	public static IEnumerable<Type> MessageTypesUnderTest => [];

	[Test]
	[MethodDataSource(nameof(MessageTypesUnderTest))]
	public async Task Test(Type type)
	{
	}
}

Expected Behavior

Described above.

Actual Behavior

Decribed above.

Steps to Reproduce

The minimal repro pasted above.

TUnit Version

1.12.15

.NET Version

.NET 10

Operating System

Linux

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions