Skip to content

Commit

Permalink
Use different FQNs for parameterized cases in TestAdapter, fix #2494
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Jan 5, 2024
1 parent b67b6b1 commit 06fb242
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/BenchmarkDotNet.TestAdapter/BenchmarkCaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ internal static TestCase ToVsTestCase(this BenchmarkCase benchmarkCase, string a
{
var benchmarkMethod = benchmarkCase.Descriptor.WorkloadMethod;
var fullClassName = benchmarkCase.Descriptor.Type.GetCorrectCSharpTypeName();
var benchmarkMethodName = benchmarkCase.Descriptor.WorkloadMethod.Name;
var benchmarkFullMethodName = $"{fullClassName}.{benchmarkMethodName}";

// Display name has arguments as well.
var displayMethodName = FullNameProvider.GetMethodName(benchmarkCase);
if (includeJobInName)
displayMethodName += $" [{benchmarkCase.GetUnrandomizedJobDisplayInfo()}]";
var parametrizedMethodName = FullNameProvider.GetMethodName(benchmarkCase);

var displayJobInfo = benchmarkCase.GetUnrandomizedJobDisplayInfo();
var displayMethodName = parametrizedMethodName + (includeJobInName ? $" [{displayJobInfo}]" : "");
var displayName = $"{fullClassName}.{displayMethodName}";

var vsTestCase = new TestCase(benchmarkFullMethodName, VsTestAdapter.ExecutorUri, assemblyPath)
// We use displayName as FQN to workaround the Rider/R# problem with FQNs processing
// See: https://github.com/dotnet/BenchmarkDotNet/issues/2494
var fullyQualifiedName = displayName;

var vsTestCase = new TestCase(fullyQualifiedName, VsTestAdapter.ExecutorUri, assemblyPath)
{
DisplayName = displayName,
Id = GetTestCaseId(benchmarkCase)
Expand Down Expand Up @@ -67,7 +67,8 @@ internal static TestCase ToVsTestCase(this BenchmarkCase benchmarkCase, string a
internal static string GetUnrandomizedJobDisplayInfo(this BenchmarkCase benchmarkCase)
{
var jobDisplayInfo = benchmarkCase.Job.DisplayInfo;
if (!benchmarkCase.Job.HasValue(CharacteristicObject.IdCharacteristic) && benchmarkCase.Job.ResolvedId.StartsWith("Job-", StringComparison.OrdinalIgnoreCase))
if (!benchmarkCase.Job.HasValue(CharacteristicObject.IdCharacteristic) &&
benchmarkCase.Job.ResolvedId.StartsWith("Job-", StringComparison.OrdinalIgnoreCase))
{
// Replace Job-ABCDEF with Job
jobDisplayInfo = "Job" + jobDisplayInfo.Substring(benchmarkCase.Job.ResolvedId.Length);
Expand All @@ -91,4 +92,4 @@ internal static Guid GetTestCaseId(this BenchmarkCase benchmarkCase)
return testIdProvider.GetId();
}
}
}
}

0 comments on commit 06fb242

Please sign in to comment.