© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
13 replies
Murphy

❔ xUnit - totally isolated serial parameterized tests?

Hopefully someone with more experience with different testing frameworks can help me out- I'm not married to using only xUnit. Though this isn't for unit testing since the test conditions depend on the file system/database state, I'm starting with xUnit just because my unit tests used it. I'm trying to find a good way to do parameterized integration tests. xUnit supports using ClassData and MemberData attributes to provide the parameters to the tests, but after a while, I found out that all the strange behavior I was seeing was due to xUnit creating instances of the parameters for all tests, all at the same time, before any test runs.

    [Theory, MemberData(nameof(StorageSystemUnderTest))]
    public async Task TestWriteNotification(IPersistentDataStorage sut){...}

    [Theory, MemberData(nameof(StorageSystemUnderTest))]
    public async Task TestAutoReload(IPersistentDataStorage sut){...}

    public static IEnumerable<object[]> StorageSystemUnderTest =>
        new List<object[]>
        {
            new object[] {  GetInMemoryStorage() },
            new object[] {  GetSystemFileStorage() },
            new object[] {  GetDatabaseStorage() },
            ...            
        };
    [Theory, MemberData(nameof(StorageSystemUnderTest))]
    public async Task TestWriteNotification(IPersistentDataStorage sut){...}

    [Theory, MemberData(nameof(StorageSystemUnderTest))]
    public async Task TestAutoReload(IPersistentDataStorage sut){...}

    public static IEnumerable<object[]> StorageSystemUnderTest =>
        new List<object[]>
        {
            new object[] {  GetInMemoryStorage() },
            new object[] {  GetSystemFileStorage() },
            new object[] {  GetDatabaseStorage() },
            ...            
        };

This is a no-go since the multiple IPersistentDataStorage objects will try to register multiple handlers with the storage providers (ie. file watchers) all at the same time and I can't have that. Is there another testing framework that would let me better control object lifetimes for use in integration tests or at least some other way to use xUnit to run tests completely serially?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ xUnit tests
C#CC# / help
3y ago
Catastrophic failure while running xunit tests
C#CC# / help
3y ago
❔ Help needed to clear database with EF between XUnit tests
C#CC# / help
3y ago