使用不同的配置执行相同的测试

Execute same test with different configurations

我有 a project supporting multiple database providers (SQL, Sqlite, InMemory). For the API tests I'm using the InMemory DB for performance reasons. For the integration tests 我想 运行 所有提供者的所有测试,以测试迁移、数据库约束等

有没有办法使用不同的配置将集成测试配置为 运行?

[编辑] 构建这样的东西?
https://github.com/xunit/xunit/issues/542 https://github.com/xunit/samples.xunit/blob/master/TestRunner/Program.cs

一旦我发现 [Theory] 解决方案就很简单了。测试执行现在指定要使用的提供程序。我已经预定义了用于每个提供程序的配置文件;正在将其复制到将要使用的配置文件并执行测试。

    [SkippableTheory]
    [InlineData("MsSql")]
    [InlineData("Sqlite")]
    [InlineData("InMemory")]
    public async Task DoesNotLoadUnspecifiedNavigationPropertiesTest(string provider)
    {
        Skip.If(provider == "MsSql" && !SkipHelper.IsWindowsOS(), "Ignore when not executing on Windows");

        async Task Test()
        {
            // Perform the test with assertions
        }

        await ExecuteTestForProvider(provider, Test);
    }

    private async Task ExecuteTestForProvider(string provider, Func<Task> test)
    {
        try
        {
            SetConfiguration(provider);
            Initialize();

            await test.Invoke();
        }
        finally
        {
            Teardown();
        }
    }

无法找到完整的实现 here