Closed dameng324 closed 3 years ago
My project file as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Pro.NBench.xUnit" Version="2.0.0" />
</ItemGroup>
</Project>
I seems found my reason. I change the test class to below:
public class TestBenchmark
{
public TestBenchmark(ITestOutputHelper output)
{
Trace.Listeners.Clear();
Trace.Listeners.Add(new XunitTraceListener(output));
}
private Counter _counter;
[PerfSetup]
public void Setup(BenchmarkContext context)
{
_counter = context.GetCounter("TestCounter");
}
[NBenchFact]
[PerfBenchmark(Description = "BytesToObjectCompressEncryptAsync on a benchmark.",
NumberOfIterations = 3, RunMode = RunMode.Throughput, RunTimeMilliseconds = 10000, TestMode = TestMode.Test)]
[CounterThroughputAssertion("TestCounter", MustBe.GreaterThan, 100.0d)]
[MemoryAssertion(MemoryMetric.TotalBytesAllocated, MustBe.LessThanOrEqualTo, ByteConstants.ThirtyTwoKb)]
[GcTotalAssertion(GcMetric.TotalCollections, GcGeneration.Gen2, MustBe.ExactlyEqualTo, 0.0d)]
public void SimpleTest()
{
_counter.Increment();
}
}
It runs well now.
Hello I have trouble with my first simple test.
Here is my code:
when I run SimpleTest in resharper Unit Test Sessions window, it run to an error below:
Please help me run my first NBench Unit Test. Thank you.