System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage不使用xunit处理异步方法

时间:2018-04-10 12:35:28

标签: c# unit-testing code-coverage xunit microsoft.codeanalysis

非常直截了当。这是一些沙盒实验的通用代码。 ExcludeFromCodeCoverage似乎适用于同步方法。没有任何runsettings或任何与覆盖相关的配置。

[ExcludeFromCodeCoverage] // Still included in coverage report.
private async Task ExecuteRetryable(Func<Task> function)
{
    try
    {
        await retryPolicyAsync.ExecuteAsync(function);
    }
    catch (Exception exception)
    {
        LogException(exception);
    }
}

[ExcludeFromCodeCoverage] // Not included in coverage report as expected.
private void LogException(Exception exception)
{
    if (TelemetryClient == null)
        return;

    var telemetry = new ExceptionTelemetry(exception);
    telemetry.Properties.Add("typeCode", "ExceptionFromTheSandbox");
    TelemetryClient.TrackException(telemetry);
    }
}

这可能是一个错误,还是我错过了什么?

0 个答案:

没有答案