@@ -111,6 +111,37 @@ public void TestClassInfoClassCleanupMethodSetShouldThrowForMultipleClassCleanup
111111 ActionUtility . ActionShouldThrowExceptionOfType ( action , typeof ( TypeInspectionException ) ) ;
112112 }
113113
114+ [ TestMethod ]
115+ public void TestClassInfoClassCleanupMethodShouldNotInvokeWhenNoTestClassInitializedIsCalled ( )
116+ {
117+ var classcleanupCallCount = 0 ;
118+ DummyTestClass . ClassCleanupMethodBody = ( ) => classcleanupCallCount ++ ;
119+
120+ this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
121+ this . testClassInfo . ClassInitializeMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassInitializeMethod" ) ;
122+
123+ var ret = this . testClassInfo . RunClassCleanup ( ) ; // call cleanup without calling init
124+
125+ Assert . AreEqual ( null , ret ) ;
126+ Assert . AreEqual ( 0 , classcleanupCallCount ) ;
127+ }
128+
129+ [ TestMethod ]
130+ public void TestClassInfoClassCleanupMethodShouldInvokeWhenTestClassInitializedIsCalled ( )
131+ {
132+ var classcleanupCallCount = 0 ;
133+ DummyTestClass . ClassCleanupMethodBody = ( ) => classcleanupCallCount ++ ;
134+
135+ this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
136+ this . testClassInfo . ClassInitializeMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassInitializeMethod" ) ;
137+
138+ this . testClassInfo . RunClassInitialize ( this . testContext ) ;
139+ var ret = this . testClassInfo . RunClassCleanup ( ) ; // call cleanup without calling init
140+
141+ Assert . AreEqual ( null , ret ) ;
142+ Assert . AreEqual ( 1 , classcleanupCallCount ) ;
143+ }
144+
114145 [ TestMethod ]
115146 public void TestClassInfoHasExecutableCleanupMethodShouldReturnFalseIfClassDoesNotHaveCleanupMethod ( )
116147 {
@@ -275,6 +306,16 @@ public void RunClassInitializeShouldThrowForAlreadyExecutedTestClassInitWithExce
275306 exception . Message ) ;
276307 }
277308
309+ [ TestMethod ]
310+ public void RunClassCleanupShouldInvokeIfClassCleanupMethod ( )
311+ {
312+ var classcleanupCallCount = 0 ;
313+ DummyTestClass . ClassCleanupMethodBody = ( ) => classcleanupCallCount ++ ;
314+ this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
315+ Assert . IsNull ( this . testClassInfo . RunClassCleanup ( ) ) ;
316+ Assert . AreEqual ( 1 , classcleanupCallCount ) ;
317+ }
318+
278319 [ TestMethod ]
279320 public void RunAssemblyInitializeShouldPassOnTheTestContextToAssemblyInitMethod ( )
280321 {
@@ -300,24 +341,13 @@ public void RunClassCleanupShouldNotInvokeIfClassCleanupIsNull()
300341 Assert . AreEqual ( 0 , classcleanupCallCount ) ;
301342 }
302343
303- [ TestMethod ]
304- public void RunClassCleanupShouldInvokeIfClassCleanupMethod ( )
305- {
306- var classcleanupCallCount = 0 ;
307- DummyTestClass . ClassCleanupMethodBody = ( ) => classcleanupCallCount ++ ;
308-
309- this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
310-
311- Assert . IsNull ( this . testClassInfo . RunClassCleanup ( ) ) ;
312- Assert . AreEqual ( 1 , classcleanupCallCount ) ;
313- }
314-
315344 [ TestMethod ]
316345 public void RunClassCleanupShouldReturnAssertFailureExceptionDetails ( )
317346 {
318347 DummyTestClass . ClassCleanupMethodBody = ( ) => UTF . Assert . Fail ( "Test Failure." ) ;
319348
320349 this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
350+
321351 StringAssert . StartsWith (
322352 this . testClassInfo . RunClassCleanup ( ) ,
323353 "Class Cleanup method DummyTestClass.ClassCleanupMethod failed. Error Message: Assert.Fail failed. Test Failure.. Stack Trace: at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassCleanupShouldReturnAssertFailureExceptionDetails>" ) ;
0 commit comments