-
-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Description
When overriding/skipping an inherited test method in a derived class that uses [InheritsTests], the source generator fails with an ArgumentException due to duplicate hint names.
Error Message
CSC : warning CS8785: Generator 'TestMetadataGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'TUnitSkipIssue_Tests_ImplementationATests_AdvancedFeature.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'.
Use Case
Multiple implementations of the same interface/abstraction need to be tested. To avoid duplicating test code, an abstract base test class contains all test cases. Each implementation has a derived test class with [InheritsTests] to run the tests against that specific implementation.
Some implementations don't support all features, so certain tests need to be skipped in specific derived classes. Overriding the test method with [Skip] seems like a natural approach, but the build fails even when just overriding without [Skip].
Minimal Reproduction
public abstract class BaseServiceTests
{
[Test]
public async Task BasicFeature()
{
await Task.CompletedTask;
}
[Test]
public async Task AdvancedFeature()
{
await Task.CompletedTask;
}
}
[InheritsTests]
public class ImplementationATests : BaseServiceTests
{
[Test]
[Skip("Implementation A does not support advanced feature")]
public new Task AdvancedFeature()
{
return Task.CompletedTask;
}
}(Note: The error occurs with or without the [Skip] attribute)
Expected Behavior
The source generator should recognize method hiding with the new keyword and only register the derived version for execution. This would allow either replacing the test implementation or skipping it with [Skip] (preferred).
Actual Behavior
The build fails because the generator attempts to create two files with the same hint name - one for the inherited test and one for the overridden test.
Environment
- TUnit Version: 1.0.78 (issue also occurs in 0.80.00)
- .NET Version: 10.0
Regression Information
This behavior worked correctly in version 0.79.0. The issue was introduced in version 0.80.0 and persists in version 1.0.78.
Question
Is using [InheritsTests] with method hiding the intended approach for skipping tests in specific implementations? If not, what is the recommended pattern for this scenario?