Skip to content

Commit 25ae7b4

Browse files
devatworkthzinc
authored andcommitted
(+semver: feature) Use DisplayName instead of methodName (#3)
This change uses the TestResult.DisplayName or TestResult.TestCase.DisplayName as the value of the name attribute of testCase elements. This has the following benefits over using the name of the test method: 1. It includes the namespace and type name for disambiguation of similarly named tests 2. In case of theory tests, it includes the values of the parameters for disambiguation The change should match the behavior of the TrxLogger, see https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs#L546 for details.
1 parent 5b3d0ed commit 25ae7b4

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/JunitTestLogger/JUnitXmlTestLogger.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ internal void TestResultHandler(object sender, TestResultEventArgs e)
190190
{
191191
TestResult result = e.Result;
192192

193+
var displayName = string.IsNullOrEmpty(result.DisplayName) ? result.TestCase.DisplayName : result.DisplayName;
194+
193195
if (TryParseName(result.TestCase.FullyQualifiedName, out var typeName, out var methodName, out _))
194196
{
195197
lock (resultsGuard)
@@ -200,7 +202,7 @@ internal void TestResultHandler(object sender, TestResultEventArgs e)
200202
result.TestCase.Source,
201203
typeName,
202204
methodName,
203-
result.TestCase.DisplayName,
205+
displayName,
204206
result.Duration,
205207
result.ErrorMessage,
206208
result.ErrorStackTrace,
@@ -369,7 +371,7 @@ private static XElement CreateTestCaseElement(TestResultInfo result)
369371
{
370372
var element = new XElement("testcase",
371373
new XAttribute("classname", result.Type),
372-
new XAttribute("name", result.Method),
374+
new XAttribute("name", result.Name),
373375
new XAttribute("time", result.Time.TotalSeconds.ToString("N7", CultureInfo.InvariantCulture)));
374376

375377
if (result.Outcome == TestOutcome.Failed)

0 commit comments

Comments
 (0)