清空 xUnit Allure 报告

问题描述 投票:0回答:1

我有两个简单的测试,通过 URL 检查站点的可访问性。两项测试均按预期工作。

IsUrlAvailableByHttp = 通过 IsUrlAvailableByHttps = 失败

但是当我使用“Allure”创建报告时 我在 Allure UI 中得到“0 个测试用例”。

我正在使用下一个命令来生成并打开报告:

allure generate
allure open

这是我的测试代码。

public class WebProtocolTest
{
    private readonly PingHelper _pingHelper;

    [AllureBefore("Setup test context")]
    public WebProtocolTest()
    {
        _pingHelper = new PingHelper();
    }

    [Fact]
    [AllureDescription("Check app availability through http")]
    public void IsUrlAvailableByHttp()
    {
        string url = "http://localhost:5001/";

        bool isUrlAvailable = _pingHelper.IsUrlAvailable(url);

        Assert.True(isUrlAvailable);
    }

    [Fact]
    [AllureDescription("Check app availability through https")]
    public void IsUrlAvailableByHttps()
    {
        string url = "https://localhost:5001/";

        bool isUrlAvailable = _pingHelper.IsUrlAvailable(url);

        Assert.True(isUrlAvailable);
    }
}

public class PingHelper
{
    public bool IsUrlAvailable(string url)
    {
        bool urlAvailable = false;

        var request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.AllowAutoRedirect = false;
        request.Method = "HEAD";
        
        try
        {
            var response = request.GetResponse();
            
            if(response != null)
            {
                urlAvailable = true;
            }
        }
        catch (WebException wex)
        {
            
        }

        return urlAvailable;
    }
}
c# xunit allure
1个回答
0
投票

反对

using allure
打开和
allure generate
- 你应该使用

allure serve "D:\%PATH to your folder%\allure-results"
© www.soinside.com 2019 - 2024. All rights reserved.