Skip to content

Commit 14b1b3d

Browse files
authored
Include namespace in test name (#225)
1 parent 36b5bdd commit 14b1b3d

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir,
6363

6464
foreach (var testCase in groupedTestCases[executable])
6565
{
66-
var key = Path.GetFullPath(testCase.Source) + ":" + testCase.FullyQualifiedName;
66+
var key = Path.GetFullPath(testCase.Source) + ":" + testCase.DisplayName;
6767
ITestPropertySettings settings;
6868
// Tests with default settings are treated as not having settings and can be run together
6969
if (_settings.TestPropertySettingsContainer.TryGetSettings(key, out settings)

GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,13 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, TestCaseLocation
253253
{
254254
if (location != null)
255255
{
256+
var ns = GetTestSignatureNamespace(location.TestClassSignature);
257+
258+
if (ns != string.Empty)
259+
ns += ".";
260+
256261
var testCase = new TestCase(
257-
descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
262+
ns + descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
258263
testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, location.Traits));
259264
return testCase;
260265
}
@@ -264,6 +269,17 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, TestCaseLocation
264269
descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
265270
}
266271

272+
internal static string GetTestSignatureNamespace(string signature)
273+
{
274+
var namespaceEnd = signature.LastIndexOf("::", StringComparison.Ordinal);
275+
if (namespaceEnd > 0)
276+
{
277+
return signature.Substring(0, namespaceEnd);
278+
}
279+
280+
return string.Empty;
281+
}
282+
267283
internal static string StripTestSymbolNamespace(string symbol)
268284
{
269285
var suffixLength = GoogleTestConstants.TestBodySignature.Length;

GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ private TestResult CreateTestResult(int indexOfTestcase)
5959
int currentLineIndex = indexOfTestcase;
6060

6161
string line = _consoleOutput[currentLineIndex++];
62-
string qualifiedTestname = RemovePrefix(line).Trim();
63-
TestCase testCase = FindTestcase(qualifiedTestname);
62+
string testDisplayName = RemovePrefix(line).Trim();
63+
TestCase testCase = FindTestcase(testDisplayName);
6464
if (testCase == null)
6565
{
6666
_logger.DebugWarning(String.Format(Resources.NoKnownTestCaseMessage, line));
@@ -189,14 +189,14 @@ private int FindIndexOfNextTestcase(int currentIndex)
189189
return -1;
190190
}
191191

192-
private TestCase FindTestcase(string qualifiedTestname)
192+
private TestCase FindTestcase(string testDisplayName)
193193
{
194-
return FindTestcase(qualifiedTestname, _testCasesRun);
194+
return FindTestcase(testDisplayName, _testCasesRun);
195195
}
196196

197-
public static TestCase FindTestcase(string qualifiedTestname, IList<TestCase> testCasesRun)
197+
public static TestCase FindTestcase(string testDisplayName, IList<TestCase> testCasesRun)
198198
{
199-
return testCasesRun.SingleOrDefault(tc => tc.FullyQualifiedName == qualifiedTestname);
199+
return testCasesRun.SingleOrDefault(tc => tc.DisplayName == testDisplayName);
200200
}
201201

202202
public static bool IsRunLine(string line)

0 commit comments

Comments
 (0)