unit-testingmvc-mini-profiler

How do you view profile information with MiniProfiler from unit tests


I am trying to profile various portions of a .Net Core 2.2 library. I decided to use unit testing since I have unit tests for many of the areas I want to profile. I am trying to use StackExchange's MiniProfiler but I don't see anything in the documentation about how to view the profiling results.

I created a property on my test fixture: public MiniProfiler Profiler { get; private set; }

and populated it in the constructor of the fixture:

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

Then call my code I want to profile:

        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);

I installed the nuget packages using: Install-Package MiniProfiler.AspNetCore -IncludePrerelease

The documentation shows a UI and talks about it but never mentions how to start the UI. I have searched the output folders and didn't find any files that resemble profile data.

Thanks


Solution

  • The unit tests doesn't have any web ui, instead it behaves almost the same as a console. Checkout this page: 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());