.net-core - 使用不同的配置执行相同的测试
问题描述
我有一个支持多个数据库提供程序(SQL、Sqlite、InMemory)的项目。对于API 测试,出于性能原因,我使用 InMemory DB。对于集成测试,我想为所有提供者运行所有测试,以测试迁移、数据库约束等。
有没有办法配置集成测试以使用不同的配置运行?
[编辑] 构建这样的东西?
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();
}
}
完整的实现可以在这里找到
推荐阅读
- javascript - 暗模式功能使用本地存储保存切换状态
- python - OpenSSL.SSL.SysCallError: (10054, 'WSAECONNRESET') 在对 ArcGIS API 的 GET 请求期间
- .net - 用 DisplayFor 显示局部变量?
- r - UNSTACK R DATAFRAME 另一列的基值
- java - google_assistant_sdk 连接超时
- c# - 解析数据库文件时ID不匹配
- javascript - 如何在 javascript 中从此类中获取 href?
- microsoft-graph-api - 列表订阅功能是否损坏?
- webpack - 更改 webpack 摘要方法
- c# - 将嵌入对象作为多部分表单数据发布