Skip to content

feat: allow class-level [MatrixDataSource] to cascade to methods with [Matrix] parameters #4765

Closed

Description

@thomhurst

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.

Activity

  1. claude commented on Feb 13, 2026

    @claude
    Contributor

    Issue Analysis

    Type: Feature Request (Enhancement) ✓

    Priority: Medium

    No Duplicates Found
    Searched for similar issues involving:

    • MatrixDataSource cascading
    • Class-level attribute inheritance
    • Matrix parameter handling

    Current Labels:

    • ✓ enhancement (already applied)

    Suggested Additional Labels:

    • help wanted - if open to community contributions

    Notes:

    • Well-documented with clear before/after examples
    • Proposed behavior is sensible: cascade only to methods with [Matrix] parameters
    • Methods without [Matrix] params unaffected
    • Explicit method-level [MatrixDataSource] can override class-level

    This is a good quality feature request with clear motivation and scope.

  2. thomhurst commented on Feb 13, 2026

    @thomhurst
    OwnerAuthor

    Closing - by design, data source attributes on a class apply to constructor parameters, not to individual test methods. [MatrixDataSource] should remain on each test method that uses [Matrix] parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions