简体   繁体   English

XUnit - 串行运行测试

[英]XUnit - run tests serially

I created few tests in XUnit (.NET CORE 5) Here is my code:我在 XUnit (.NET CORE 5) 中创建了一些测试这是我的代码:

public class SerialTest
{
    [Fact]
    public async Task Test1()
    {
        await Task.Delay(TimeSpan.FromSeconds(5));
        Assert.True(true);
    }

    [Fact]
    public async Task Test2()
    {
        await Task.Delay(TimeSpan.FromSeconds(5));
        Assert.True(true);
    }
}

This tests should work serially - Test1 should be finished before Test 2. But it's not happening.这个测试应该连续工作 - Test1 应该在 Test 2 之前完成。但它没有发生。 This is how its working:这是它的工作方式: 在此处输入图像描述

How to change it?如何改变它?

The usual response to this is that well constructed unit tests should be able to run in any order, but...对此的通常反应是结构良好的单元测试应该能够以任何顺序运行,但是......

https://hamidmosalla.com/2018/08/16/xunit-control-the-test-execution-order/ https://hamidmosalla.com/2018/08/16/xunit-control-the-test-execution-order/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM