如何使用 MiniProfiler 从单元测试中查看配置文件信息

How do you view profile information with MiniProfiler from unit tests

我正在尝试分析 .Net Core 2.2 库的各个部分。我决定使用单元测试,因为我对许多我想要分析的领域进行了单元测试。我正在尝试使用 StackExchange 的 MiniProfiler,但我在文档中没有看到任何关于如何查看分析结果的内容。

我在我的测试夹具上创建了一个 属性: public MiniProfiler 探查器 { 得到; 私有集; }

并将其填充到夹具的构造函数中:

this.Profiler = MiniProfiler.StartNew("CRMODataDataSource Profiler");

然后调用我要分析的代码:

        using (Fixture.Profiler.Step("TestDefaultWithDynamic"))
        {
            testValue =
                (testEntity.HasPrimaryKey() == true)
                && testEntity.GetPrimaryKey().KeyValues.All(v =>
                {
                    if (null != v.Value)
                    {
                        return !CrmEntityFixture.ValueIsDefault((dynamic)v.Value);
                    }
                    return false;
                }
                );
        }
        Assert.True(testValue);

我使用以下方法安装了 nuget 包: 安装包 MiniProfiler.AspNetCore -IncludePrerelease

documentation 显示了一个 UI 并谈论它但从未提及如何启动 UI。我搜索了输出文件夹,但没有找到任何类似于配置文件数据的文件。

谢谢

单元测试没有任何网络 ui,相反它的行为几乎与控制台相同。 查看此页面:https://miniprofiler.com/dotnet/ConsoleDotNetCore

// Default configuration usually works for most, but override, you can call:
// MiniProfiler.Configure(new MiniProfilerOptions { ... });

var profiler = MiniProfiler.StartNew("My Profiler Name");
using (profiler.Step("Main Work"))
{
    // Do some work...
}

Console.WriteLine(profiler.RenderPlainText());
// or for the active profiler:
Console.WriteLine(MiniProfiler.Current.RenderPlainText());