@@ -22,7 +22,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
22
22
/// </summary>
23
23
internal sealed class UnitTestRunner : MarshalByRefObject
24
24
{
25
- private readonly ConcurrentDictionary < string , TestMethodInfo > _fixtureTests = new ( ) ;
25
+ private readonly ConcurrentDictionary < string , TestAssemblyInfo > _assemblyFixtureTests = new ( ) ;
26
+ private readonly ConcurrentDictionary < string , TestClassInfo > _classFixtureTests = new ( ) ;
26
27
private readonly TypeCache _typeCache ;
27
28
private readonly ReflectHelper _reflectHelper ;
28
29
private readonly ClassCleanupManager _classCleanupManager ;
@@ -92,33 +93,29 @@ internal FixtureTestResult GetFixtureTestResult(TestMethod testMethod, string fi
92
93
{
93
94
// For the fixture methods, we need to return the appropriate result.
94
95
// Get matching testMethodInfo from the cache and return UnitTestOutcome for the fixture test.
95
- if ( _fixtureTests . TryGetValue ( testMethod . AssemblyName + testMethod . FullClassName , out TestMethodInfo ? testMethodInfo ) )
96
+ if ( fixtureType is Constants . ClassInitializeFixtureTrait or Constants . ClassCleanupFixtureTrait &&
97
+ _classFixtureTests . TryGetValue ( testMethod . AssemblyName + testMethod . FullClassName , out TestClassInfo ? testClassInfo ) )
96
98
{
97
- if ( fixtureType == Constants . ClassInitializeFixtureTrait )
99
+ UnitTestOutcome outcome = fixtureType switch
98
100
{
99
- return testMethodInfo . Parent . IsClassInitializeExecuted
100
- ? new ( true , GetOutcome ( testMethodInfo . Parent . ClassInitializationException ) )
101
- : new ( true , UnitTestOutcome . Inconclusive ) ;
102
- }
101
+ Constants . ClassInitializeFixtureTrait => testClassInfo . IsClassInitializeExecuted ? GetOutcome ( testClassInfo . ClassInitializationException ) : UnitTestOutcome . Inconclusive ,
102
+ Constants . ClassCleanupFixtureTrait => testClassInfo . IsClassCleanupExecuted ? GetOutcome ( testClassInfo . ClassCleanupException ) : UnitTestOutcome . Inconclusive ,
103
+ _ => throw ApplicationStateGuard . Unreachable ( ) ,
104
+ } ;
103
105
104
- if ( fixtureType == Constants . ClassCleanupFixtureTrait )
105
- {
106
- return testMethodInfo . Parent . IsClassInitializeExecuted
107
- ? new ( true , GetOutcome ( testMethodInfo . Parent . ClassCleanupException ) )
108
- : new ( true , UnitTestOutcome . Inconclusive ) ;
109
- }
106
+ return new FixtureTestResult ( true , outcome ) ;
110
107
}
111
-
112
- if ( _fixtureTests . TryGetValue ( testMethod . AssemblyName , out testMethodInfo ) )
108
+ else if ( fixtureType is Constants . AssemblyInitializeFixtureTrait or Constants . AssemblyCleanupFixtureTrait &&
109
+ _assemblyFixtureTests . TryGetValue ( testMethod . AssemblyName , out TestAssemblyInfo ? testAssemblyInfo ) )
113
110
{
114
- if ( fixtureType == Constants . AssemblyInitializeFixtureTrait )
111
+ Exception ? exception = fixtureType switch
115
112
{
116
- return new ( true , GetOutcome ( testMethodInfo . Parent . Parent . AssemblyInitializationException ) ) ;
117
- }
118
- else if ( fixtureType == Constants . AssemblyCleanupFixtureTrait )
119
- {
120
- return new ( true , GetOutcome ( testMethodInfo . Parent . Parent . AssemblyCleanupException ) ) ;
121
- }
113
+ Constants . AssemblyInitializeFixtureTrait => testAssemblyInfo . AssemblyInitializationException ,
114
+ Constants . AssemblyCleanupFixtureTrait => testAssemblyInfo . AssemblyCleanupException ,
115
+ _ => throw ApplicationStateGuard . Unreachable ( ) ,
116
+ } ;
117
+
118
+ return new ( true , GetOutcome ( exception ) ) ;
122
119
}
123
120
124
121
return new ( false , UnitTestOutcome . Inconclusive ) ;
@@ -165,8 +162,8 @@ internal async Task<TestResult[]> RunSingleTestAsync(TestMethod testMethod, IDic
165
162
DebugEx . Assert ( testMethodInfo is not null , "testMethodInfo should not be null." ) ;
166
163
167
164
// Keep track of all non-runnable methods so that we can return the appropriate result at the end.
168
- _fixtureTests . TryAdd ( testMethod . AssemblyName , testMethodInfo ) ;
169
- _fixtureTests . TryAdd ( testMethod . AssemblyName + testMethod . FullClassName , testMethodInfo ) ;
165
+ _assemblyFixtureTests . TryAdd ( testMethod . AssemblyName , testMethodInfo . Parent . Parent ) ;
166
+ _classFixtureTests . TryAdd ( testMethod . AssemblyName + testMethod . FullClassName , testMethodInfo . Parent ) ;
170
167
171
168
ITestContext testContextForAssemblyInit = PlatformServiceProvider . Instance . GetTestContext ( testMethod , writer , properties , messageLogger , testContextForTestExecution . Context . CurrentTestOutcome ) ;
172
169
0 commit comments