如何调试Async XUnit单元测试?

时间:2018-11-20 11:54:39

标签: c# unit-testing asynchronous async-await xunit

我已经使用XUnit在asp.net核心代码上创建了一些单元测试。

我正试图致电我的服务控制器并检查结果:

    [Fact]
    public async Task TryGetData()
    {
        //Arrange
        WeatherController weatherController = new WeatherController();

        //Act
        ActionResult result = await weatherController.Get();

        //Assert
        JsonResult jsonResult = Assert.IsType<JsonResult>(result);
        List<Prediction> predictions = Assert.IsType<List<Prediction>>(jsonResult.Value);
        Assert.NotEmpty(predictions);
        foreach (Prediction prediction in predictions)
        {
            Assert.NotEqual(default(DateTime), prediction.Date);
            Assert.NotEqual(default(double), prediction.Temperature);
        }
    }

它可以正常工作,现在暂时在“温度”为0时失败。

但是:

  1. 如果我执行了调试,测试将失败,但是Visual Studio不会在其上停止
  2. 如果我设置了一个断点,那么一切都不会停止。

我使用的是VS2019 Xunit 2.4.1,在resharper测试会话中进行了尝试,而从Visual Studio进行的测试则没有任何改变。

是否支持?我读到某个地方在XUnit 1.9之前不支持此功能,但我使用的是2.4.1。

知道发生了什么吗?

0 个答案:

没有答案
相关问题