77using Microsoft . VisualStudio . TestPlatform . MSTest . TestAdapter . Execution ;
88using Microsoft . VisualStudio . TestPlatform . MSTest . TestAdapter . Helpers ;
99using Microsoft . VisualStudio . TestPlatform . MSTest . TestAdapter . ObjectModel ;
10- using Microsoft . VisualStudio . TestPlatform . MSTestAdapter . PlatformServices ;
11- using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
1210using Microsoft . VisualStudio . TestTools . UnitTesting ;
1311using Microsoft . VisualStudio . TestTools . UnitTesting . Internal ;
1412
@@ -69,8 +67,6 @@ internal AssemblyEnumerationResult EnumerateAssembly(string assemblyFileName)
6967 List < string > warnings = [ ] ;
7068 DebugEx . Assert ( ! StringEx . IsNullOrWhiteSpace ( assemblyFileName ) , "Invalid assembly file name." ) ;
7169 var tests = new List < UnitTestElement > ( ) ;
72- // Contains list of assembly/class names for which we have already added fixture tests.
73- var fixturesTests = new HashSet < string > ( ) ;
7470
7571 Assembly assembly = PlatformServiceProvider . Instance . FileOperations . LoadAssembly ( assemblyFileName ) ;
7672
@@ -94,7 +90,7 @@ internal AssemblyEnumerationResult EnumerateAssembly(string assemblyFileName)
9490 foreach ( Type type in types )
9591 {
9692 List < UnitTestElement > testsInType = DiscoverTestsInType ( assemblyFileName , type , warnings , discoverInternals ,
97- dataSourcesUnfoldingStrategy , fixturesTests ) ;
93+ dataSourcesUnfoldingStrategy ) ;
9894 tests . AddRange ( testsInType ) ;
9995 }
10096
@@ -154,8 +150,7 @@ private List<UnitTestElement> DiscoverTestsInType(
154150 Type type ,
155151 List < string > warningMessages ,
156152 bool discoverInternals ,
157- TestDataSourceUnfoldingStrategy dataSourcesUnfoldingStrategy ,
158- HashSet < string > fixturesTests )
153+ TestDataSourceUnfoldingStrategy dataSourcesUnfoldingStrategy )
159154 {
160155 string ? typeFullName = null ;
161156 var tests = new List < UnitTestElement > ( ) ;
@@ -172,12 +167,6 @@ private List<UnitTestElement> DiscoverTestsInType(
172167 {
173168 if ( _typeCache . GetTestMethodInfoForDiscovery ( test . TestMethod ) is { } testMethodInfo )
174169 {
175- // Add fixture tests like AssemblyInitialize, AssemblyCleanup, ClassInitialize, ClassCleanup.
176- if ( MSTestSettings . CurrentSettings . ConsiderFixturesAsSpecialTests )
177- {
178- AddFixtureTests ( testMethodInfo , tests , fixturesTests ) ;
179- }
180-
181170 if ( TryUnfoldITestDataSources ( test , testMethodInfo , dataSourcesUnfoldingStrategy , tests ) )
182171 {
183172 continue ;
@@ -200,88 +189,6 @@ private List<UnitTestElement> DiscoverTestsInType(
200189 return tests ;
201190 }
202191
203- private static void AddFixtureTests ( DiscoveryTestMethodInfo testMethodInfo , List < UnitTestElement > tests , HashSet < string > fixtureTests )
204- {
205- string assemblyName = testMethodInfo . Parent . Parent . Assembly . GetName ( ) . Name ! ;
206- string assemblyLocation = testMethodInfo . Parent . Parent . Assembly . Location ;
207- string classFullName = testMethodInfo . Parent . ClassType . FullName ! ;
208-
209- // Check if fixtures for this assembly has already been added.
210- if ( ! fixtureTests . Contains ( assemblyLocation ) )
211- {
212- _ = fixtureTests . Add ( assemblyLocation ) ;
213-
214- // Add AssemblyInitialize and AssemblyCleanup fixture tests if they exist.
215- if ( testMethodInfo . Parent . Parent . AssemblyInitializeMethod is not null )
216- {
217- tests . Add ( GetAssemblyFixtureTest ( testMethodInfo . Parent . Parent . AssemblyInitializeMethod , assemblyName ,
218- classFullName , assemblyLocation , EngineConstants . AssemblyInitializeFixtureTrait ) ) ;
219- }
220-
221- if ( testMethodInfo . Parent . Parent . AssemblyCleanupMethod is not null )
222- {
223- tests . Add ( GetAssemblyFixtureTest ( testMethodInfo . Parent . Parent . AssemblyCleanupMethod , assemblyName ,
224- classFullName , assemblyLocation , EngineConstants . AssemblyCleanupFixtureTrait ) ) ;
225- }
226- }
227-
228- // Check if fixtures for this class has already been added.
229- if ( ! fixtureTests . Contains ( assemblyLocation + classFullName ) )
230- {
231- _ = fixtureTests . Add ( assemblyLocation + classFullName ) ;
232-
233- // Add ClassInitialize and ClassCleanup fixture tests if they exist.
234- if ( testMethodInfo . Parent . ClassInitializeMethod is not null )
235- {
236- tests . Add ( GetClassFixtureTest ( testMethodInfo . Parent . ClassInitializeMethod , classFullName ,
237- assemblyLocation , EngineConstants . ClassInitializeFixtureTrait ) ) ;
238- }
239-
240- if ( testMethodInfo . Parent . ClassCleanupMethod is not null )
241- {
242- tests . Add ( GetClassFixtureTest ( testMethodInfo . Parent . ClassCleanupMethod , classFullName ,
243- assemblyLocation , EngineConstants . ClassCleanupFixtureTrait ) ) ;
244- }
245- }
246-
247- static UnitTestElement GetAssemblyFixtureTest ( MethodInfo methodInfo , string assemblyName , string classFullName ,
248- string assemblyLocation , string fixtureType )
249- {
250- string methodName = GetMethodName ( methodInfo ) ;
251- string [ ] hierarchy = [ null ! , assemblyName , EngineConstants . AssemblyFixturesHierarchyClassName , methodName ] ;
252- return GetFixtureTest ( classFullName , assemblyLocation , fixtureType , methodName , hierarchy , methodInfo ) ;
253- }
254-
255- static UnitTestElement GetClassFixtureTest ( MethodInfo methodInfo , string classFullName ,
256- string assemblyLocation , string fixtureType )
257- {
258- string methodName = GetMethodName ( methodInfo ) ;
259- string [ ] hierarchy = [ null ! , classFullName , methodName ] ;
260- return GetFixtureTest ( classFullName , assemblyLocation , fixtureType , methodName , hierarchy , methodInfo ) ;
261- }
262-
263- static string GetMethodName ( MethodInfo methodInfo )
264- {
265- ParameterInfo [ ] args = methodInfo . GetParameters ( ) ;
266- return args . Length > 0
267- ? $ "{ methodInfo . Name } ({ string . Join ( ',' , args . Select ( a => a . ParameterType . FullName ) ) } )"
268- : methodInfo . Name ;
269- }
270-
271- static UnitTestElement GetFixtureTest ( string classFullName , string assemblyLocation , string fixtureType , string methodName , string [ ] hierarchy , MethodInfo methodInfo )
272- {
273- string displayName = $ "[{ fixtureType } ] { methodName } ";
274- var method = new TestMethod ( classFullName , methodName , hierarchy , methodName , classFullName , assemblyLocation , displayName , null )
275- {
276- MethodInfo = methodInfo ,
277- } ;
278- return new UnitTestElement ( method )
279- {
280- Traits = [ new Trait ( EngineConstants . FixturesTestTrait , fixtureType ) ] ,
281- } ;
282- }
283- }
284-
285192 private static bool TryUnfoldITestDataSources ( UnitTestElement test , DiscoveryTestMethodInfo testMethodInfo , TestDataSourceUnfoldingStrategy dataSourcesUnfoldingStrategy , List < UnitTestElement > tests )
286193 {
287194 // It should always be `true`, but if any part of the chain is obsolete; it might not contain those.
0 commit comments