@@ -63,23 +63,25 @@ private void OnTestSkipped(TestSkippedInfo info)
6363 public int RunTests ( )
6464 {
6565 var assembly = Assembly . GetExecutingAssembly ( ) ;
66- var testrunner = AssemblyRunner . WithoutAppDomain ( assembly . Location ) ;
67- testrunner . OnDiscoveryComplete = OnDiscoveryComplete ;
68- testrunner . OnExecutionComplete = OnExecutionComplete ;
69- testrunner . OnTestFailed = OnTestFailed ;
70- testrunner . OnTestSkipped = OnTestSkipped ;
71-
72- Console . WriteLine ( "Discovering tests..." ) ;
73- testrunner . Start ( parallelAlgorithm : null ) ;
74-
75- Finished . WaitOne ( ) ;
76- Finished . Dispose ( ) ;
77-
78- // Wait for assembly runner to finish.
79- // If we try to dispose while runner is executing,
80- // it will throw an error.
81- while ( testrunner . Status != AssemblyRunnerStatus . Idle )
82- Thread . Sleep ( 100 ) ;
66+ using ( var testrunner = AssemblyRunner . WithoutAppDomain ( assembly . Location ) )
67+ {
68+ testrunner . OnDiscoveryComplete = OnDiscoveryComplete ;
69+ testrunner . OnExecutionComplete = OnExecutionComplete ;
70+ testrunner . OnTestFailed = OnTestFailed ;
71+ testrunner . OnTestSkipped = OnTestSkipped ;
72+
73+ Console . WriteLine ( "Discovering tests..." ) ;
74+ testrunner . Start ( parallelAlgorithm : null ) ;
75+
76+ Finished . WaitOne ( ) ;
77+ Finished . Dispose ( ) ;
78+
79+ // Wait for assembly runner to finish.
80+ // If we try to dispose while runner is executing,
81+ // it will throw an error.
82+ while ( testrunner . Status != AssemblyRunnerStatus . Idle )
83+ Thread . Sleep ( 100 ) ;
84+ }
8385 return Result ;
8486 }
8587
0 commit comments