Skip to content

Commit 90b3dc8

Browse files
Merge pull request #285 from microsoft/dev/elmorrow/fixturenode
Adding optional node in Test Explorer for SetUpTestSuite or TearDownTestSuite fixture method results
2 parents 79ad488 + f152863 commit 90b3dc8

19 files changed

Lines changed: 173 additions & 6 deletions

GoogleTestAdapter/Core/GoogleTestConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public static class GoogleTestConstants
3030
public const string FilterOption = " --gtest_filter=";
3131

3232
public const string TestBodySignature = "::TestBody";
33+
public const string SetUpFixtureMethod = "SetUpTestSuite";
34+
public const string TearDownFixtureMethod = "TearDownTestSuite";
3335
public const string ParameterizedTestMarker = " # GetParam() = ";
3436
public const string TypedTestMarker = ". # TypeParam = ";
3537

GoogleTestAdapter/Core/Helpers/Extensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// This file has been modified by Microsoft on 7/2017.
22

3+
using System;
34
using System.Collections.Generic;
5+
using System.Linq;
46
using GoogleTestAdapter.Model;
57

68
namespace GoogleTestAdapter.Helpers
@@ -14,6 +16,12 @@ public static IEnumerable<T> Yield<T>(this T item)
1416
yield return item;
1517
}
1618

19+
public static (IEnumerable<T> predicateTrue, IEnumerable<T> predicateFalse) Partition<T>(this IEnumerable<T> list, Func<T, bool> predicate)
20+
{
21+
var meetsCondition = list.Where(t => predicate(t));
22+
return (meetsCondition, list.Except(meetsCondition));
23+
}
24+
1725
internal static IDictionary<string, List<TestCase>> GroupByExecutable(this IEnumerable<TestCase> testcases)
1826
{
1927
var groupedTestCases = new Dictionary<string, List<TestCase>>();

GoogleTestAdapter/Core/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoogleTestAdapter/Core/Resources.resx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@
154154
<data name="CategoryRuntimeBehaviorName" xml:space="preserve">
155155
<value>Runtime behavior</value>
156156
</data>
157-
<data name="CategoryTestExecutionName" xml:space="preserve">
158-
<value>Test execution</value>
159-
</data>
160157
<data name="CategoryTraitsName" xml:space="preserve">
161158
<value>Regexes for trait assignment</value>
162159
</data>
@@ -435,6 +432,12 @@ Placeholders:</value>
435432
Google Test option: {0}</value>
436433
<comment>{0} represents a command-line flag.</comment>
437434
</data>
435+
<data name="OptionShowFixtureMethodNode" xml:space="preserve">
436+
<value>Show fixture method node</value>
437+
</data>
438+
<data name="OptionShowFixtureMethodNodeDescription" xml:space="preserve">
439+
<value>Show placeholder nodes in test explorer representing status of fixture methods. </value>
440+
</data>
438441
<data name="OptionShowReleaseNotes" xml:space="preserve">
439442
<value>Show release notes after update</value>
440443
</data>
@@ -656,4 +659,7 @@ Placeholders:</value>
656659
<value>XmlNode could not be parsed: '{0}'. Exception message: {1}</value>
657660
<comment>{0} represents an unlocalized name of an XML node, {1} represents localized exception message (e.g. "Cannot load file")</comment>
658661
</data>
662+
<data name="CategoryTestExecutionName" xml:space="preserve">
663+
<value>Test execution</value>
664+
</data>
659665
</root>

GoogleTestAdapter/Core/Runners/TestResultCollector.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using GoogleTestAdapter.Common;
7+
using GoogleTestAdapter.Helpers;
78
using GoogleTestAdapter.Model;
89
using GoogleTestAdapter.TestResults;
910

@@ -23,7 +24,18 @@ public TestResultCollector(ILogger logger, string threadName)
2324
public List<TestResult> CollectTestResults(IEnumerable<TestCase> testCasesRun, List<string> consoleOutput, TestCase crashedTestCase)
2425
{
2526
var testResults = new List<TestResult>();
26-
TestCase[] arrTestCasesRun = testCasesRun as TestCase[] ?? testCasesRun.ToArray();
27+
28+
bool isFixtureMethodCase(TestCase tc)
29+
{
30+
var testType = tc.Traits.FirstOrDefault(t => t.Name.Equals(TestCases.TestCaseDescriptor.TestTypeTraitName));
31+
return testType != null && Enum.TryParse(testType.Value, out TestCases.TestCaseDescriptor.TestTypes type) && type == TestCases.TestCaseDescriptor.TestTypes.Fixture;
32+
}
33+
34+
(var fixtureMethods, var remainingCases) = testCasesRun.Partition(isFixtureMethodCase);
35+
TestCase[] arrTestCasesRun = remainingCases as TestCase[] ?? remainingCases.ToArray();
36+
TestCase[] arrFixtureMethods = fixtureMethods as TestCase[] ?? fixtureMethods.ToArray();
37+
38+
CreateFixtureMethodResults(arrFixtureMethods, testResults);
2739

2840
var consoleParser = new StandardOutputTestResultParser(arrTestCasesRun, consoleOutput, _logger);
2941
if (testResults.Count < arrTestCasesRun.Length)
@@ -81,11 +93,20 @@ private void CreateMissingResults(TestCase[] testCases, TestCase crashedTestCase
8193
_logger.DebugInfo(String.Format(Resources.CreatedTestResults, _threadName, testCases.Length));
8294
}
8395

96+
private void CreateFixtureMethodResults(TestCase[] testCases, List<TestResult> testResults)
97+
{
98+
foreach (TestCase testCase in testCases)
99+
{
100+
testResults.Add(StandardOutputTestResultParser.CreatePassedTestResult(testCase, TimeSpan.FromMilliseconds(0)));
101+
}
102+
}
103+
84104
private void ReportSuspiciousTestCases(TestCase[] testCases)
85105
{
86106
string testCasesAsString = string.Join(Environment.NewLine, testCases.Select(tc => tc.DisplayName));
87107
_logger.DebugWarning(String.Format(Resources.TestCaseNotRun, _threadName, testCases.Length, Environment.NewLine, testCasesAsString));
88108
}
89109

110+
90111
}
91112
}

GoogleTestAdapter/Core/Settings/IGoogleTestAdapterSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public interface IGoogleTestAdapterSettings
2727
bool? ParallelTestExecution { get; set; }
2828
bool? PrintTestOutput { get; set; }
2929
bool? RunDisabledTests { get; set; }
30+
bool? ShowFixtureMethodNode { get; set; }
3031
bool? ShuffleTests { get; set; }
3132
int? ShuffleTestsSeed { get; set; }
3233
string TestDiscoveryRegex { get; set; }
@@ -79,6 +80,7 @@ public static void GetUnsetValuesFrom(this IGoogleTestAdapterSettings self, IGoo
7980
self.TimestampOutput = self.TimestampOutput ?? other.TimestampOutput;
8081
self.ShowReleaseNotes = self.ShowReleaseNotes ?? other.ShowReleaseNotes;
8182
self.KillProcessesOnCancel = self.KillProcessesOnCancel ?? other.KillProcessesOnCancel;
83+
self.ShowFixtureMethodNode = self.ShowFixtureMethodNode ?? other.ShowFixtureMethodNode;
8284

8385
self.UseNewTestExecutionFramework = self.UseNewTestExecutionFramework ?? other.UseNewTestExecutionFramework;
8486

GoogleTestAdapter/Core/Settings/RunSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public RunSettings(string projectRegex)
4747
public virtual int? NrOfTestRepetitions { get; set; }
4848
public bool ShouldSerializeNrOfTestRepetitions() { return NrOfTestRepetitions != null; }
4949

50+
public virtual bool? ShowFixtureMethodNode { get; set; }
51+
public bool ShouldSerializeShowFixtureMethodNode() { return ShowFixtureMethodNode != null; }
52+
53+
5054
public virtual bool? ShuffleTests { get; set; }
5155
public bool ShouldSerializeShuffleTests() { return ShuffleTests != null; }
5256

GoogleTestAdapter/Core/Settings/SettingsWrapper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ public virtual int NrOfTestRepetitions
475475
}
476476
}
477477

478+
public static readonly string OptionShowFixtureMethodNode = Resources.OptionShowFixtureMethodNode;
479+
public const bool OptionShowFixtureMethodNodeDefaultValue = false;
480+
public static readonly string OptionShowFixtureMethodNodeDescription = Resources.OptionShowFixtureMethodNodeDescription;
481+
482+
public virtual bool ShowFixtureMethodNode => _currentSettings.ShowFixtureMethodNode ?? OptionShowFixtureMethodNodeDefaultValue;
483+
478484

479485
public static readonly string OptionShuffleTests = Resources.OptionShuffleTests;
480486
public const bool OptionShuffleTestsDefaultValue = false;

GoogleTestAdapter/Core/TestCases/MethodSignatureCreator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal IEnumerable<string> GetTestMethodSignatures(TestCaseDescriptor descript
2020
return GetParameterizedTestMethodSignature(descriptor).Yield();
2121
case TestCaseDescriptor.TestTypes.Simple:
2222
return GetTestMethodSignature(descriptor.Suite, descriptor.Name).Yield();
23+
case TestCaseDescriptor.TestTypes.Fixture:
24+
return GetFixtureMethodSignature(descriptor.Suite, descriptor.Name).Yield();
2325
default:
2426
throw new InvalidOperationException(String.Format(Resources.UnknownLiteral, descriptor.TestType));
2527
}
@@ -69,6 +71,11 @@ private string GetTestMethodSignature(string suite, string testCase, string type
6971
return suite + "_" + testCase + "_Test" + typeParam + GoogleTestConstants.TestBodySignature;
7072
}
7173

74+
private string GetFixtureMethodSignature(string suite, string testCase)
75+
{
76+
return suite + "::" + testCase;
77+
}
78+
7279
}
7380

7481
}

GoogleTestAdapter/Core/TestCases/NewTestCaseResolver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal TestCaseLocation FindTestCaseLocation(List<string> testMethodSignatures
5151
result = DoFindTestCaseLocation(testMethodSignatures);
5252
}
5353
return result;
54-
}
54+
}
5555

5656
private void LoadSymbolsFromImports()
5757
{
@@ -73,6 +73,8 @@ private void AddSymbolsFromBinary(string binary)
7373
try
7474
{
7575
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*" + GoogleTestConstants.TestBodySignature));
76+
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*::" + GoogleTestConstants.SetUpFixtureMethod));
77+
_allTestMethodSymbols.AddRange(diaResolver.GetFunctions("*::" + GoogleTestConstants.TearDownFixtureMethod));
7678
_allTraitSymbols.AddRange(diaResolver.GetFunctions("*" + TraitAppendix));
7779

7880
_logger.DebugInfo(String.Format(Resources.FoundTestMethod, _allTestMethodSymbols.Count, _allTraitSymbols.Count, binary));

0 commit comments

Comments
 (0)