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

.net core 使用不同的配置执行相同的测试,.net-core,integration-testing,xunit,.net Core,Integration Testing,Xunit,我支持多个数据库提供者(SQL、Sqlite、InMemory)。出于性能原因,我使用InMemory DB。例如,我想为所有提供者运行所有测试,以测试迁移、DB约束等 有没有办法将集成测试配置为使用不同的配置运行 [编辑]构建类似这样的内容? 一旦我发现了[理论]这个解决方案是微不足道的。测试执行现在指定要使用的提供程序。我已经预定义了用于每个提供者的配置文件;这将被复制到将要使用的配置文件中,并执行测试 [SkippableTheory] [InlineData("MsSql

我支持多个数据库提供者(SQL、Sqlite、InMemory)。出于性能原因,我使用InMemory DB。例如,我想为所有提供者运行所有测试,以测试迁移、DB约束等

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

[编辑]构建类似这样的内容?

一旦我发现了
[理论]
这个解决方案是微不足道的。测试执行现在指定要使用的提供程序。我已经预定义了用于每个提供者的配置文件;这将被复制到将要使用的配置文件中,并执行测试

    [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();
        }
    }
[跳跃理论]
[在线数据(“MsSql”)]
[InlineData(“Sqlite”)]
[InlineData(“InMemory”)]
公共异步任务DoesNotLoadUnspecifiedNavigationPropertieTest(字符串提供程序)
{
Skip.If(provider==“MsSql”&&&!SkipHelper.IsWindowsOS(),“不在Windows上执行时忽略”);
异步任务测试()
{
//使用断言执行测试
}
等待ExecuteTestForProvider(提供程序,测试);
}
专用异步任务ExecuteTestForProvider(字符串提供程序,Func测试)
{
尝试
{
设置配置(提供者);
初始化();
等待test.Invoke();
}
最后
{
撕裂();
}
}

一旦我发现了
[理论]
解决方案是微不足道的,就可以找到完整的实现。测试执行现在指定要使用的提供程序。我已经预定义了用于每个提供者的配置文件;这将被复制到将要使用的配置文件中,并执行测试

    [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();
        }
    }
[跳跃理论]
[在线数据(“MsSql”)]
[InlineData(“Sqlite”)]
[InlineData(“InMemory”)]
公共异步任务DoesNotLoadUnspecifiedNavigationPropertieTest(字符串提供程序)
{
Skip.If(provider==“MsSql”&&&!SkipHelper.IsWindowsOS(),“不在Windows上执行时忽略”);
异步任务测试()
{
//使用断言执行测试
}
等待ExecuteTestForProvider(提供程序,测试);
}
专用异步任务ExecuteTestForProvider(字符串提供程序,Func测试)
{
尝试
{
设置配置(提供者);
初始化();
等待test.Invoke();
}
最后
{
撕裂();
}
}
可以找到完整的实现