-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Problem
When a class has multiple test methods using `[Matrix]` parameters, `[MatrixDataSource]` must be repeated on every method:
```csharp
[Category("Search")]
public class ProductSearchTests
{
[Test]
[MatrixDataSource] // must repeat
public async Task Search_Returns_Results(
[Matrix("electronics", "clothing", "books")] string category,
[Matrix("price_asc", "price_desc", "name")] string sortBy) { }
[Test]
[MatrixDataSource] // must repeat again
public async Task Pagination_Works(
[Matrix(1, 2, 3)] int page,
[Matrix(2, 5)] int pageSize) { }
}
```
Placing `[MatrixDataSource]` on the class doesn't work - you get TUnit0049 errors on each method.
Proposed Behavior
`[MatrixDataSource]` on the class should cascade to any method that has `[Matrix]` parameters:
```csharp
[MatrixDataSource] // applies to all methods with [Matrix] params
public class ProductSearchTests
{
[Test]
public async Task Search_Returns_Results(
[Matrix("electronics", "clothing", "books")] string category,
[Matrix("price_asc", "price_desc", "name")] string sortBy) { }
[Test]
public async Task Pagination_Works(
[Matrix(1, 2, 3)] int page,
[Matrix(2, 5)] int pageSize) { }
[Test]
public async Task Non_Matrix_Test() { } // no [Matrix] params, unaffected
}
```
Methods without `[Matrix]` parameters would be unaffected. Methods with explicit `[MatrixDataSource]` would override the class-level attribute if needed.
Context
Discovered while building the CloudShop Aspire + TUnit example (#4761). The `ProductSearchTests` class had to repeat the attribute on every method.