使用xUnit 2.4.1,我正在寻找一种方法,使其在动态跳过集成测试时达到我的要求.
我知道xUnit不是为集成测试而设计的,但我无意将xUnit用于某些测试,将Not个xUnit用于其他测试.我认为单元测试和集成测试之间的区别对于测试运行者来说是非常无用的.
有了这些,我有了一些依赖于数据库的测试.我在测试中添加了以下特征.
public class Some_database_interaction
{
[Fact]
[Trait("Demand", "SqlServer")]
public async Task One_thing_is_inserted()
{
using var connection = await Connect();
var applicationService = new SomeService(connection);
var resultCount = await applicationService.DoTheImportantThing("some args", true);
Assert.Equal(1, resultCount);
}
}
目前,当我不想运行依赖于数据库的测试时,我使用命令跳过这些测试.
dotnet test --filter Demand!=SqlServer
这可以在CI管道中使用,但我不能期望团队成员每次都键入此命令.
相反,我想要某种方式来检测功能,然后在需求未得到满足时跳过测试.不过我不知道怎么做.
到目前为止,我最好的try 是以捕捉错误和短路测试的形式为测试添加噪声.
SqlConnection connection;
try
{
connection = await Connect();
}
catch
{
// Exit the test
return;
}
using connection;
var applicationService = new SomeService(connection);
但这有一个不希望的副作用,即显示测试成功而不是被跳过.
有没有关于从这里go 哪里的提示?我知道xUnit 3会有断言.Skip(),但目前我仍停留在xUnit 2上.