【问题标题】:The next xUnit test starts to run before previous cleanup in IClassFixture下一个 xUnit 测试在 IClassFixture 中的上一次清理之前开始运行
【发布时间】:2017-01-09 19:48:19
【问题描述】:

在 ASP.NET Core 中使用 "xunit": "2.2.0-beta4-build3444" 我有两个集成测试,它们与同一个数据库表交互并使用 IClassFixture 为一些数据提供种子:

// FooTestData inserts two rows in TableA
// In FooTestData.Dispose() the rows are deleted
public class FooTest : IClassFixture<FooTestData>
{
    [Fact]
    public void Test()
    {
        var result = GetAllRowsFromTableA()
        // Assert that result.Count == 2
    }

}

// BarTestData inserts one row in TableA
// In BarTestData.Dispose() the row is deleted
public class BarTest: IClassFixture<BarTestData>
{
    [Fact]
    public void Test()
    {
        // Do something
    }
}

FooTest.Test 失败,因为它在调用 BarTestData.Dispose() 之前启动。如果我一次运行所有测试(而不是并行运行),数据库中的行数为 3。我该如何解决?

更新似乎测试是并行运行的,即使我告诉他们不要这样做(不在 Visual Studio 中选择“并行运行”)

【问题讨论】:

    标签: .net-core xunit


    【解决方案1】:

    https://xunit.github.io/docs/running-tests-in-parallel.html

    默认情况下,xunit > 2.0 会并行运行两个测试,无论我告诉 Visual Studio 做什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 2019-06-07
      • 2013-04-25
      • 2012-09-16
      • 2018-03-11
      • 1970-01-01
      相关资源
      最近更新 更多