Skip to content

Commit 3424420

Browse files
Merge pull request #238 from microsoft/dev/davidraygoza/NSTestsFix
Fix Bug: Namespace Tests Do Not Run
2 parents 02ed1bf + d194648 commit 3424420

8 files changed

Lines changed: 37 additions & 42 deletions

File tree

GoogleTestAdapter/Core.Tests/Scheduling/TestDurationSerializerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void ReadTestDurations_DurationFileWithoutCurrentTest_EmptyDictionary()
125125
serializer.UpdateTestDurations(testResults);
126126

127127
IDictionary<Model.TestCase, int> durations = serializer.ReadTestDurations(
128-
new Model.TestCase("TestSuite1.Test2", tempFile, "TestSuite1.Test2", "", 0).Yield());
128+
new Model.TestCase("TestSuite1.Test2", "TestSuite1.Test2", tempFile, "TestSuite1.Test2", "", 0).Yield());
129129

130130
durations.Should().NotBeNull();
131131
durations.Count.Should().Be(0);

GoogleTestAdapter/Core/Model/TestCase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class TestCase
77
public string Source { get; }
88

99
public string FullyQualifiedName { get; }
10+
public string FullyQualifiedNameWithNamespace { get; }
1011
public string DisplayName { get; }
1112

1213
public string CodeFilePath { get; }
@@ -15,9 +16,10 @@ public class TestCase
1516
public List<Trait> Traits { get; } = new List<Trait>();
1617
public List<TestProperty> Properties { get; } = new List<TestProperty>();
1718

18-
public TestCase(string fullyQualifiedName, string source, string displayName, string codeFilePath, int lineNumber)
19+
public TestCase(string fullyQualifiedName, string fullyQualifiedNameWithNamespace, string source, string displayName, string codeFilePath, int lineNumber)
1920
{
2021
FullyQualifiedName = fullyQualifiedName;
22+
FullyQualifiedNameWithNamespace = fullyQualifiedNameWithNamespace;
2123
Source = source;
2224
DisplayName = displayName;
2325
CodeFilePath = codeFilePath;

GoogleTestAdapter/Core/Model/TestCaseMetaDataProperty.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ public class TestCaseMetaDataProperty : TestProperty
1010

1111
public int NrOfTestCasesInSuite { get; }
1212
public int NrOfTestCasesInExecutable { get; }
13+
public string FullyQualifiedNameWithoutNamespace { get; }
1314

14-
public TestCaseMetaDataProperty(int nrOfTestCasesInSuite, int nrOfTestCasesInExecutable)
15-
: this($"{nrOfTestCasesInSuite}:{nrOfTestCasesInExecutable}")
15+
public TestCaseMetaDataProperty(int nrOfTestCasesInSuite, int nrOfTestCasesInExecutable, string fullyQualifiedNameWithoutNamespace)
16+
: this($"{nrOfTestCasesInSuite}|{nrOfTestCasesInExecutable}|{fullyQualifiedNameWithoutNamespace}")
1617
{
1718
}
1819

1920
public TestCaseMetaDataProperty(string serialization) : base(serialization)
2021
{
21-
int[] values = serialization.Split(':').Select(int.Parse).ToArray();
22-
if (values.Length != 2)
22+
string[] fields = serialization.Split('|');
23+
if (fields.Length != 3)
2324
throw new ArgumentException(serialization, nameof(serialization));
24-
NrOfTestCasesInSuite = values[0];
25-
NrOfTestCasesInExecutable = values[1];
25+
NrOfTestCasesInSuite = int.Parse(fields[0]);
26+
NrOfTestCasesInExecutable = int.Parse(fields[1]);
27+
FullyQualifiedNameWithoutNamespace = fields[2];
2628
}
2729
}
2830
}

GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public IList<TestCase> CreateTestCases(Action<TestCase> reportTestCase = null)
8787
{
8888
foreach (var testCase in suiteTestCasesPair.Value)
8989
{
90-
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count));
90+
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count, testCase.FullyQualifiedName));
9191
}
9292
}
9393

@@ -179,7 +179,7 @@ private IList<TestCase> NewCreateTestcases(Action<TestCase> reportTestCase, List
179179
{
180180
foreach (var testCase in suiteTestCasesPair.Value)
181181
{
182-
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count));
182+
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasesPair.Value.Count, testCases.Count, testCase.FullyQualifiedName));
183183
reportTestCase?.Invoke(testCase);
184184
}
185185
}
@@ -232,7 +232,7 @@ private Dictionary<string, TestCaseLocation> GetTestCaseLocations(IList<TestCase
232232
private TestCase CreateTestCase(TestCaseDescriptor descriptor)
233233
{
234234
var testCase = new TestCase(
235-
descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
235+
descriptor.FullyQualifiedName, descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
236236
testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, new List<Trait>()));
237237
return testCase;
238238
}
@@ -259,14 +259,14 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, TestCaseLocation
259259
ns += ".";
260260

261261
var testCase = new TestCase(
262-
ns + descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
262+
descriptor.FullyQualifiedName, ns + descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
263263
testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, location.Traits));
264264
return testCase;
265265
}
266266

267267
_logger.LogWarning(String.Format(Resources.LocationNotFoundError, descriptor.FullyQualifiedName));
268268
return new TestCase(
269-
descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
269+
descriptor.FullyQualifiedName, descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
270270
}
271271

272272
internal static string GetTestSignatureNamespace(string signature)

GoogleTestAdapter/Core/TestResults/StandardOutputTestResultParser.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,7 @@ private TestCase FindTestcase(string qualifiedTestname)
196196

197197
public static TestCase FindTestcase(string qualifiedTestname, IList<TestCase> testCasesRun)
198198
{
199-
foreach (TestCase tc in testCasesRun)
200-
{
201-
// If namespace exists then remove it so we can compare the test display names.
202-
// Using just tc.DisplayName does not work for paramaterized test cases.
203-
string fullyQualifiedName = tc.FullyQualifiedName;
204-
int frequency = fullyQualifiedName.Where(x => (x == '.')).Count();
205-
if (frequency > 1)
206-
{
207-
fullyQualifiedName = fullyQualifiedName.Substring(fullyQualifiedName.IndexOf('.') + 1);
208-
}
209-
210-
if (fullyQualifiedName == qualifiedTestname)
211-
{
212-
return tc;
213-
}
214-
}
215-
216-
return null;
199+
return testCasesRun.SingleOrDefault(tc => tc.FullyQualifiedName == qualifiedTestname);
217200
}
218201

219202
public static bool IsRunLine(string line)

GoogleTestAdapter/TestAdapter/DataConversionExtensions.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,28 @@ static DataConversionExtensions()
3030

3131
public static TestCase ToTestCase(this VsTestCase vsTestCase)
3232
{
33-
var testCase = new TestCase(vsTestCase.FullyQualifiedName, vsTestCase.Source,
33+
TestCaseMetaDataProperty metaData = null;
34+
var metaDataSerialization = vsTestCase.GetPropertyValue(TestMetaDataProperty);
35+
if (metaDataSerialization != null)
36+
metaData = new TestCaseMetaDataProperty((string)metaDataSerialization);
37+
38+
var fullyQualifiedNameWithoutNamespace = vsTestCase.FullyQualifiedName;
39+
if (metaData != null)
40+
fullyQualifiedNameWithoutNamespace = metaData.FullyQualifiedNameWithoutNamespace;
41+
42+
var testCase = new TestCase(fullyQualifiedNameWithoutNamespace, vsTestCase.FullyQualifiedName, vsTestCase.Source,
3443
vsTestCase.DisplayName, vsTestCase.CodeFilePath, vsTestCase.LineNumber);
3544
testCase.Traits.AddRange(vsTestCase.Traits.Select(ToTrait));
3645

37-
var metaDataSerialization = vsTestCase.GetPropertyValue(TestMetaDataProperty);
38-
if (metaDataSerialization != null)
39-
testCase.Properties.Add(new TestCaseMetaDataProperty((string)metaDataSerialization));
46+
if (metaData != null)
47+
testCase.Properties.Add(metaData);
4048

4149
return testCase;
4250
}
4351

4452
public static VsTestCase ToVsTestCase(this TestCase testCase)
4553
{
46-
var vsTestCase = new VsTestCase(testCase.FullyQualifiedName, TestExecutor.ExecutorUri, testCase.Source)
54+
var vsTestCase = new VsTestCase(testCase.FullyQualifiedNameWithNamespace, TestExecutor.ExecutorUri, testCase.Source)
4755
{
4856
DisplayName = testCase.DisplayName,
4957
CodeFilePath = testCase.CodeFilePath,
@@ -52,9 +60,9 @@ public static VsTestCase ToVsTestCase(this TestCase testCase)
5260

5361
vsTestCase.Traits.AddRange(testCase.Traits.Select(ToVsTrait));
5462

55-
var property = testCase.Properties.OfType<TestCaseMetaDataProperty>().SingleOrDefault();
56-
if (property != null)
57-
vsTestCase.SetPropertyValue(TestMetaDataProperty, property.Serialization);
63+
var metaData = testCase.Properties.OfType<TestCaseMetaDataProperty>().SingleOrDefault();
64+
if (metaData != null)
65+
vsTestCase.SetPropertyValue(TestMetaDataProperty, metaData.Serialization);
5866

5967
return vsTestCase;
6068
}

GoogleTestAdapter/TestAdapter/TestExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void TryRunTests(IEnumerable<string> executables, IRunContext runContext
9898
filter.Filter(allTestCasesInExecutables.Select(tc => tc.ToVsTestCase())).ToList();
9999
ICollection<TestCase> testCasesToRun =
100100
allTestCasesInExecutables.Where(
101-
tc => vsTestCasesToRun.Any(vtc => tc.FullyQualifiedName == vtc.FullyQualifiedName)).ToArray();
101+
tc => vsTestCasesToRun.Any(vtc => tc.FullyQualifiedNameWithNamespace == vtc.FullyQualifiedName)).ToArray();
102102

103103
DoRunTests(testCasesToRun, runContext, frameworkHandle);
104104

GoogleTestAdapter/Tests.Common/TestDataCreator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<TestCase> GetTestCases(params string[] qualifiedNames)
7070

7171
public TestCase ToTestCase(string name, string executable, string sourceFile = "")
7272
{
73-
return new TestCase(name, executable, name, sourceFile, 0);
73+
return new TestCase(name, name,executable, name, sourceFile, 0);
7474
}
7575

7676
public TestCase ToTestCase(string name)
@@ -109,7 +109,7 @@ public IEnumerable<TestCase> CreateDummyTestCasesFull(string[] qualifiedNamesToR
109109
{
110110
if (qualifiedNamesToRun.Contains(testCase.FullyQualifiedName))
111111
{
112-
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasePair.Value.Count, allQualifiedNames.Length));
112+
testCase.Properties.Add(new TestCaseMetaDataProperty(suiteTestCasePair.Value.Count, allQualifiedNames.Length, testCase.FullyQualifiedName));
113113
testCases.Add(testCase);
114114
}
115115
}

0 commit comments

Comments
 (0)