C#C
C#9mo ago
WolfDK

Issues running BenchmarkDotNet fron NUnit test

I am trying to have BenchmarkDotNet run a Benchmark when running (NUnit) tests for one of my services.
However the Benchmark fails with 'Build Error'.
My whole project has no trouble building and running, so i don't understand what its issue is...

I have included the testlog, for anybody who wish to look through that...

My test that runs the Benchmark is the following.

c#
[Test]
public void BenchmarkPerformance()
{
    ManualConfig config = ManualConfig.Create(DefaultConfig.Instance)
        .WithOptions(ConfigOptions.DisableOptimizationsValidator).AddLogger(ConsoleLogger.Default)
        .AddExporter(MarkdownExporter.GitHub).AddExporter(HtmlExporter.Default).AddExporter(JsonExporter.Default)
        .AddValidator(JitOptimizationsValidator.DontFailOnError).AddFilter(new ExcludeAssembliesFilter("Uno"));

    Summary? summary = BenchmarkRunner.Run<AppliedKeywordServiceBenchmarks>(config);
}

private class ExcludeAssembliesFilter : IFilter
{
    private readonly string[] _excludedAssemblies;

    public ExcludeAssembliesFilter(params string[] excludedAssemblies)
    {
        _excludedAssemblies = excludedAssemblies;
    }

    public bool Predicate(BenchmarkCase benchmarkCase)
    {
        foreach (string assembly in _excludedAssemblies)
        {
            if (benchmarkCase.Descriptor.Type.Assembly.FullName.Contains(assembly))
            {
                return false;
            }
        }

        return true;
    }
}
Was this page helpful?