我有两个简单的测试,通过 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;
}
}
反对
using allure
打开和 allure generate
- 你应该使用
allure serve "D:\%PATH to your folder%\allure-results"