@@ -111,6 +111,37 @@ public void TestClassInfoClassCleanupMethodSetShouldThrowForMultipleClassCleanup
111
111
ActionUtility . ActionShouldThrowExceptionOfType ( action , typeof ( TypeInspectionException ) ) ;
112
112
}
113
113
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
+
114
145
[ TestMethod ]
115
146
public void TestClassInfoHasExecutableCleanupMethodShouldReturnFalseIfClassDoesNotHaveCleanupMethod ( )
116
147
{
@@ -275,6 +306,16 @@ public void RunClassInitializeShouldThrowForAlreadyExecutedTestClassInitWithExce
275
306
exception . Message ) ;
276
307
}
277
308
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
+
278
319
[ TestMethod ]
279
320
public void RunAssemblyInitializeShouldPassOnTheTestContextToAssemblyInitMethod ( )
280
321
{
@@ -300,24 +341,13 @@ public void RunClassCleanupShouldNotInvokeIfClassCleanupIsNull()
300
341
Assert . AreEqual ( 0 , classcleanupCallCount ) ;
301
342
}
302
343
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
-
315
344
[ TestMethod ]
316
345
public void RunClassCleanupShouldReturnAssertFailureExceptionDetails ( )
317
346
{
318
347
DummyTestClass . ClassCleanupMethodBody = ( ) => UTF . Assert . Fail ( "Test Failure." ) ;
319
348
320
349
this . testClassInfo . ClassCleanupMethod = typeof ( DummyTestClass ) . GetMethod ( "ClassCleanupMethod" ) ;
350
+
321
351
StringAssert . StartsWith (
322
352
this . testClassInfo . RunClassCleanup ( ) ,
323
353
"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