Skip to content

Commit 9e2f850

Browse files
Merge pull request #251 from microsoft/dev/gcampbell/FixParameterizedWorkingDirectory
Fix parameterized test settings
2 parents 67195fd + c3c6aca commit 9e2f850

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using GoogleTestAdapter.Model;
1313
using GoogleTestAdapter.Framework;
1414
using GoogleTestAdapter.Settings;
15+
using GoogleTestAdapter.TestCases;
1516

1617
namespace GoogleTestAdapter.Runners
1718
{
@@ -64,6 +65,18 @@ public void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir,
6465
foreach (var testCase in groupedTestCases[executable])
6566
{
6667
var key = Path.GetFullPath(testCase.Source) + ":" + testCase.FullyQualifiedName;
68+
69+
var testType = testCase.Traits.FirstOrDefault(t => t.Name.Equals(nameof(TestCaseDescriptor.TestType)));
70+
71+
// If it is a parameterized test, we should look for the "parent" key which doesn't have the suite or the id defined in the xml file.
72+
// The strategy for this can also be seen in the MethodSignatureCreate.cs file, going the other way.
73+
if (testType != null && Enum.TryParse(testType.Value, out TestCaseDescriptor.TestTypes type) && type == TestCaseDescriptor.TestTypes.Parameterized)
74+
{
75+
int firstIndex = testCase.FullyQualifiedName.IndexOf("/");
76+
int lastIndex = testCase.FullyQualifiedName.LastIndexOf("/");
77+
key = string.Concat(Path.GetFullPath(testCase.Source), ":", "*", testCase.FullyQualifiedName.Substring(firstIndex, lastIndex - firstIndex), "/*");
78+
}
79+
6780
ITestPropertySettings settings;
6881
// Tests with default settings are treated as not having settings and can be run together
6982
if (_settings.TestPropertySettingsContainer.TryGetSettings(key, out settings)

GoogleTestAdapter/Core/TestCases/TestCaseFactory.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor)
234234
var testCase = new TestCase(
235235
descriptor.FullyQualifiedName, descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
236236
testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, new List<Trait>()));
237+
238+
// Add the TestType for use in the executor when constructing the test key.
239+
testCase.Traits.Add(new Trait(nameof(TestCaseDescriptor.TestType), descriptor.TestType.ToString()));
237240
return testCase;
238241
}
239242

@@ -261,12 +264,19 @@ private TestCase CreateTestCase(TestCaseDescriptor descriptor, TestCaseLocation
261264
var testCase = new TestCase(
262265
descriptor.FullyQualifiedName, ns + descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
263266
testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, location.Traits));
267+
268+
// Add the TestType for use in the executor when constructing the test key.
269+
testCase.Traits.Add(new Trait(nameof(TestCaseDescriptor.TestType), descriptor.TestType.ToString()));
264270
return testCase;
265271
}
266272

267-
_logger.LogWarning(String.Format(Resources.LocationNotFoundError, descriptor.FullyQualifiedName));
268-
return new TestCase(
273+
var returnTest = new TestCase(
269274
descriptor.FullyQualifiedName, descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
275+
276+
// Add the TestType for use in the executor when constructing the test key.
277+
returnTest.Traits.Add(new Trait(nameof(TestCaseDescriptor.TestType), descriptor.TestType.ToString()));
278+
_logger.LogWarning(String.Format(Resources.LocationNotFoundError, descriptor.FullyQualifiedName));
279+
return returnTest;
270280
}
271281

272282
internal static string GetTestSignatureNamespace(string signature)

0 commit comments

Comments
 (0)