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

时间:2019-05-08 09:51:57

标签: .net-core integration-testing xunit

我有a project支持多个数据库提供程序(SQL,Sqlite,InMemory)。对于API tests,出于性能原因,我正在使用InMemory数据库。对于integration tests,我想为所有提供商运行所有测试,以测试迁移,数据库约束等。

是否可以配置集成测试以在不同的配置下运行?

[edit]构建类似这样的内容?
https://github.com/xunit/xunit/issues/542 https://github.com/xunit/samples.xunit/blob/master/TestRunner/Program.cs

1 个答案:

答案 0 :(得分:0)

一旦我发现[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

相关问题