1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright © 2000-2003 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright © 2000-2003 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
33 using System.Collections;
34 using System.Reflection;
38 /// Summary description for TestSuite.
42 public class TestSuite : Test
44 private static readonly string EXPLICIT_SELECTION_REQUIRED = "Explicit selection required";
49 /// Our collection of child tests
51 private ArrayList tests = new ArrayList();
54 /// The fixture setup method for this suite
56 protected MethodInfo fixtureSetUp;
59 /// The fixture teardown method for this suite
61 protected MethodInfo fixtureTearDown;
64 /// True if the fixture has been set up
72 public TestSuite( string name ) : this( name, 0 ) { }
74 public TestSuite( string name, int assemblyKey )
75 : base( name, assemblyKey )
80 public TestSuite( string parentSuiteName, string name )
81 : this( parentSuiteName, name, 0 ) { }
83 public TestSuite( string parentSuiteName, string name, int assemblyKey )
84 : base( parentSuiteName, name, assemblyKey )
89 public TestSuite( Type fixtureType ) : base( fixtureType, 0 ) { }
91 public TestSuite( Type fixtureType, int assemblyKey ) : base( fixtureType, assemblyKey ) { }
93 protected TestSuite( object fixture ) : base( fixture, 0 ) { }
95 protected TestSuite( object fixture, int assemblyKey ) : base( fixture, assemblyKey ) { }
103 foreach( Test test in Tests )
105 TestSuite suite = test as TestSuite;
111 public void Add( Test test )
115 test.ShouldRun = ShouldRun;
116 test.IgnoreReason = IgnoreReason;
122 //Keep this in for testing for the time being
123 public void Add( object fixture )
125 Add( new TestFixture( fixture ) );
130 public override ArrayList Tests
132 get { return tests; }
135 public override bool IsSuite
140 public override bool IsTestCase
142 get { return false; }
147 get { return isSetUp; }
148 set { isSetUp = value; }
154 /// True if this is a fixture. May populate the test's
155 /// children as a side effect.
156 /// TODO: An easier way to tell this?
158 public override bool IsFixture
162 // We have no way of constructing an empty suite unless it's a fixture
163 if ( Tests.Count == 0 ) return true;
165 // Any suite with children is a fixture if the children are test cases
166 Test firstChild = (Test)Tests[0];
167 return !firstChild.IsSuite;
171 public override int CountTestCases()
175 foreach(Test test in Tests)
177 count += test.CountTestCases();
182 public override int CountTestCases(IFilter filter)
186 if(this.Filter(filter))
188 foreach(Test test in Tests)
190 count += test.CountTestCases(filter);
196 public override TestResult Run(EventListener listener)
198 return Run( listener, null );
201 public override TestResult Run(EventListener listener, IFilter filter)
203 TestSuiteResult suiteResult = new TestSuiteResult(this, Name);
205 listener.SuiteStarted(this);
206 long startTime = DateTime.Now.Ticks;
210 suiteResult.Executed = true;
211 DoSetUp( suiteResult );
213 RunAllTests( suiteResult, listener, filter );
215 DoTearDown( suiteResult );
218 suiteResult.NotRun(this.IgnoreReason);
220 long stopTime = DateTime.Now.Ticks;
221 double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
222 suiteResult.Time = time;
224 listener.SuiteFinished(suiteResult);
228 public virtual void DoSetUp( TestResult suiteResult )
232 public virtual void DoTearDown( TestResult suiteResult )
236 protected virtual void RunAllTests(
237 TestSuiteResult suiteResult, EventListener listener, IFilter filter )
239 foreach(Test test in ArrayList.Synchronized(Tests))
241 bool saveShouldRun = test.ShouldRun;
245 if (this.ShouldRun == false)
247 test.ShouldRun = false;
248 test.IgnoreReason = this.IgnoreReason;
250 else if ( test.IsExplicit && filter == null )
252 test.ShouldRun = false;
253 test.IgnoreReason = EXPLICIT_SELECTION_REQUIRED;
257 if ( filter == null || test.Filter( filter ) )
259 suiteResult.AddResult( test.Run( listener, filter ) );
262 if ( saveShouldRun && !test.ShouldRun )
264 test.ShouldRun = true;
265 test.IgnoreReason = null;
270 public override bool Filter(IFilter filter)
272 return filter.Pass(this);