Is the feature request related to a problem
Yes:
Background
I recently migrated a test suite from Verify.xUnit to Verify.TUnit. The migration surfaced two differences in snapshot filename generation that frictioned the migration path for me. This is about finding ways to improve the migration experience.
Context: how I understand xUnit and TUnit differ in fixture injection
In xUnit, infrastructure fixtures are injected via IClassFixture<T> / ICollectionFixture<T> - a mechanism that is completely separate from test method parameters. As a result, fixture types are invisible to Verify.xUnit's naming logic.
TUnit uses the same mechanisms for shared infrastructure fixtures (e.g. [ClassDataSource<T>(Shared = SharedType.PerTestSession)]) and test data shared across multiple test cases. Verify.TUnit therefore includes all constructor parameters in the parameters list alongside method parameters.
Current behaviour: constructor parameters (incl. infrastructure fixtures) appear in snapshot filenames
When a TUnit test class has a constructor parameter that carries a shared fixture - e.g., a test database - the fixture's parameter name appears in the generated snapshot filename:
MyTests.MyTest_testDatabaseFixture=MyNamespace.TestDatabaseFixture_days=7_flag=True.verified.txt
Currently this can be worked around at Verify callsite:
await Verify(result).IgnoreParameters("testDatabaseFixture");
I think this must be repeated on every Verify() call in every fixture-using class, since IgnoreParameters is not available on global VerifierSettings.
Describe the solution
Possible improvement: a global API such as VerifierSettings.IgnoreParameters<T>() (or VerifierSettings.IgnoreClassArguments()) that would provide an opt-out of fixture-type parameters across the board, without touching individual Verify() calls. Or, maybe it could make sense to provide exclusion based on SharedType.
Describe alternatives considered
- updating all
Verify callsites
- renaming all
verified files
Additional context
The MWE below uses file-based apps.
MWE: infrastructure fixture appears in snapshot filename
mwe1.cs
#:property TargetFramework=net10.0
#:property PublishAot=false
#:package TUnit@1.*
#:package Verify.TUnit@31.13.*
using System.Runtime.CompilerServices;
public static class ModuleInit
{
[ModuleInitializer]
public static void Init() => VerifierSettings.AutoVerify();
}
public class TestDatabaseFixture;
[ClassDataSource<TestDatabaseFixture>(Shared = SharedType.PerTestSession)]
public class MweTests(TestDatabaseFixture testDatabaseFixture)
{
// Desired filename: MweTests.TestWithFixture_days=7_active=True.verified.txt
// Actual filename: MweTests.TestWithFixture_testDatabaseFixture=TestDatabaseFixture_days=7_active=True.verified.txt
[Test]
[Arguments(7, true)]
[Arguments(14, false)]
public Task TestWithFixture(int days, bool active)
=> Verify(new { days, active });
[Test]
[Arguments(7, true)]
[Arguments(14, false)]
public Task TestWithFixtureAndWorkaround(int days, bool active)
=> Verify(new { days, active }).IgnoreParameters(nameof(testDatabaseFixture));
}
The fixture's parameter name (testDatabaseFixture) and type appear in the filename. For a test migrated from xUnit (where fixtures were invisible to Verify), every .verified.txt file from such a class would need renaming, or every Verify() call would need .IgnoreParameters("testDatabaseFixture") added.
Is there any existing recommended configuration that doesn't require changing all Verify-callsites?
Thank you for creating Verify! I really enjoy using it in multiple projects 🚀♥️
Is the feature request related to a problem
Yes:
Background
I recently migrated a test suite from Verify.xUnit to Verify.TUnit. The migration surfaced two differences in snapshot filename generation that frictioned the migration path for me. This is about finding ways to improve the migration experience.
Context: how I understand xUnit and TUnit differ in fixture injection
In xUnit, infrastructure fixtures are injected via
IClassFixture<T>/ICollectionFixture<T>- a mechanism that is completely separate from test method parameters. As a result, fixture types are invisible to Verify.xUnit's naming logic.TUnit uses the same mechanisms for shared infrastructure fixtures (e.g.
[ClassDataSource<T>(Shared = SharedType.PerTestSession)]) and test data shared across multiple test cases. Verify.TUnit therefore includes all constructor parameters in the parameters list alongside method parameters.Current behaviour: constructor parameters (incl. infrastructure fixtures) appear in snapshot filenames
When a TUnit test class has a constructor parameter that carries a shared fixture - e.g., a test database - the fixture's parameter name appears in the generated snapshot filename:
Currently this can be worked around at
Verifycallsite:I think this must be repeated on every
Verify()call in every fixture-using class, sinceIgnoreParametersis not available on globalVerifierSettings.Describe the solution
Possible improvement: a global API such as
VerifierSettings.IgnoreParameters<T>()(orVerifierSettings.IgnoreClassArguments()) that would provide an opt-out of fixture-type parameters across the board, without touching individualVerify()calls. Or, maybe it could make sense to provide exclusion based onSharedType.Describe alternatives considered
VerifycallsitesverifiedfilesAdditional context
MWE: infrastructure fixture appears in snapshot filename
mwe1.csThe fixture's parameter name (
testDatabaseFixture) and type appear in the filename. For a test migrated from xUnit (where fixtures were invisible to Verify), every.verified.txtfile from such a class would need renaming, or everyVerify()call would need.IgnoreParameters("testDatabaseFixture")added.Is there any existing recommended configuration that doesn't require changing all
Verify-callsites?Thank you for creating Verify! I really enjoy using it in multiple projects 🚀♥️