Skip to content

Commit fa6f746

Browse files
author
Lukasz Mendakiewicz (from Dev Box)
committed
proof of concept
1 parent 4937770 commit fa6f746

6 files changed

Lines changed: 34 additions & 42 deletions

File tree

GoogleTestAdapter/Core/Model/TestCase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ public class TestCase
66
{
77
public string Source { get; }
88

9-
public string FullyQualifiedName { get; set; }
9+
public string FullyQualifiedName { get; }
10+
public string FullyQualifiedNameWithNamespace { get; }
1011
public string DisplayName { get; }
1112

1213
public string CodeFilePath { get; }
1314
public int LineNumber { get; }
1415

15-
public string Namespace { get; set; }
16-
1716
public List<Trait> Traits { get; } = new List<Trait>();
1817
public List<TestProperty> Properties { get; } = new List<TestProperty>();
1918

20-
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)
2120
{
2221
FullyQualifiedName = fullyQualifiedName;
22+
FullyQualifiedNameWithNamespace = fullyQualifiedNameWithNamespace;
2323
Source = source;
2424
DisplayName = displayName;
2525
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/Runners/SequentialTestRunner.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,6 @@ public static void LogExecutionError(ILogger logger, string executable, string w
180180
private IEnumerable<TestResult> TryRunTests(string executable, string workingDir, IDictionary<string, string> envVars, bool isBeingDebugged,
181181
IDebuggedProcessLauncher debuggedLauncher, CommandLineGenerator.Args arguments, IProcessExecutor executor, StreamingStandardOutputTestResultParser streamingParser)
182182
{
183-
foreach (TestCase tc in arguments.TestCases)
184-
{
185-
// If namespace exists then remove it so we can compare the test display names.
186-
// Using just tc.DisplayName does not work for paramaterized test cases.
187-
string fullyQualifiedName = tc.FullyQualifiedName;
188-
int frequency = fullyQualifiedName.Where(x => (x == '.')).Count();
189-
if (frequency > 1)
190-
{
191-
string ns = fullyQualifiedName.Substring(0, fullyQualifiedName.IndexOf('.'));
192-
tc.Namespace = ns;
193-
_logger.LogInfo("NS removing: " + tc.Namespace);
194-
fullyQualifiedName = fullyQualifiedName.Substring(fullyQualifiedName.IndexOf('.') + 1);
195-
}
196-
197-
tc.FullyQualifiedName = fullyQualifiedName;
198-
_logger.LogInfo("Test Name after removing NS: " + tc.FullyQualifiedName);
199-
}
200-
201183
List<string> consoleOutput;
202184
if (_settings.UseNewTestExecutionFramework)
203185
{

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/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

0 commit comments

Comments
 (0)