~adam-rpconnelly/nunit-3.0/bug-483845

« back to all changes in this revision

Viewing changes to src/framework/Internal/TestSuite.cs

  • Committer: Charlie Poole
  • Date: 2010-01-08 17:21:03 UTC
  • Revision ID: charlie@nunit.com-20100108172103-o065jps8sbft4hhq
Further simplification of API and internals: Removing TestInfo and NUnitFramework classes, eliminating all references to the framework from the test runner and using xml to communicate results back to the runner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
namespace NUnit.Framework.Internal
32
32
{
33
 
        /// <summary>
34
 
        /// Summary description for TestSuite.
35
 
        /// </summary>
36
 
        /// 
 
33
    /// <summary>
 
34
    /// TestSuite represents a composite test, which contains other tests.
 
35
    /// </summary>
37
36
        [Serializable]
38
37
        public class TestSuite : Test
39
38
        {
86
85
        #endregion
87
86
 
88
87
                #region Constructors
 
88
        /// <summary>
 
89
        /// Initializes a new instance of the <see cref="TestSuite"/> class.
 
90
        /// </summary>
 
91
        /// <param name="name">The name of the suite.</param>
89
92
                public TestSuite( string name ) 
90
93
                        : base( name ) { }
91
94
 
 
95
        /// <summary>
 
96
        /// Initializes a new instance of the <see cref="TestSuite"/> class.
 
97
        /// </summary>
 
98
        /// <param name="parentSuiteName">Name of the parent suite.</param>
 
99
        /// <param name="name">The name of the suite.</param>
92
100
                public TestSuite( string parentSuiteName, string name ) 
93
101
                        : base( parentSuiteName, name ) { }
94
102
 
 
103
        /// <summary>
 
104
        /// Initializes a new instance of the <see cref="TestSuite"/> class.
 
105
        /// </summary>
 
106
        /// <param name="fixtureType">Type of the fixture.</param>
95
107
        public TestSuite(Type fixtureType)
96
108
            : this(fixtureType, null) { }
97
109
 
 
110
        /// <summary>
 
111
        /// Initializes a new instance of the <see cref="TestSuite"/> class.
 
112
        /// </summary>
 
113
        /// <param name="fixtureType">Type of the fixture.</param>
 
114
        /// <param name="arguments">The arguments.</param>
98
115
        public TestSuite(Type fixtureType, object[] arguments)
99
116
            : base(fixtureType.FullName)
100
117
        {
111
128
        #endregion
112
129
 
113
130
                #region Public Methods
 
131
        /// <summary>
 
132
        /// Sorts tests under this suite.
 
133
        /// </summary>
114
134
                public void Sort()
115
135
                {
116
136
            if (!maintainTestOrder)
127
147
                }
128
148
 
129
149
#if false
 
150
        /// <summary>
 
151
        /// Sorts tests under this suite using the specified comparer.
 
152
        /// </summary>
 
153
        /// <param name="comparer">The comparer.</param>
130
154
        public void Sort(IComparer comparer)
131
155
        {
132
156
                        this.tests.Sort(comparer);
140
164
                }
141
165
#endif
142
166
 
 
167
        /// <summary>
 
168
        /// Adds a test to the suite.
 
169
        /// </summary>
 
170
        /// <param name="test">The test.</param>
143
171
                public void Add( Test test ) 
144
172
                {
145
173
//                      if( test.RunState == RunState.Runnable )
151
179
                        tests.Add(test);
152
180
                }
153
181
 
 
182
        /// <summary>
 
183
        /// Adds a pre-constructed test fixture to the suite.
 
184
        /// </summary>
 
185
        /// <param name="fixture">The fixture.</param>
154
186
                public void Add( object fixture )
155
187
                {
156
188
                        Test test = TestFixtureBuilder.BuildFrom( fixture );
160
192
                #endregion
161
193
 
162
194
                #region Properties
 
195
        /// <summary>
 
196
        /// Gets this test's child tests
 
197
        /// </summary>
 
198
        /// <value></value>
163
199
                public override IList Tests 
164
200
                {
165
201
                        get { return tests; }
166
202
                }
167
203
 
 
204
        /// <summary>
 
205
        /// Indicates whether this test is a suite
 
206
        /// </summary>
 
207
        /// <value></value>
168
208
                public override bool IsSuite
169
209
                {
170
210
                        get { return true; }
171
211
                }
172
212
 
 
213
        /// <summary>
 
214
        /// Gets a count of test cases represented by
 
215
        /// or contained under this test.
 
216
        /// </summary>
 
217
        /// <value></value>
173
218
                public override int TestCount
174
219
                {
175
220
                        get
184
229
                        }
185
230
                }
186
231
 
 
232
        /// <summary>
 
233
        /// Gets the Type of the fixture used in running this test
 
234
        /// </summary>
 
235
        /// <value></value>
187
236
        public override Type FixtureType
188
237
        {
189
238
            get { return fixtureType; }
190
239
        }
191
240
 
 
241
        /// <summary>
 
242
        /// Gets or sets a fixture object for running this test
 
243
        /// </summary>
 
244
        /// <value></value>
192
245
        public override object Fixture
193
246
        {
194
247
            get { return fixture; }
195
248
            set { fixture = value; }
196
249
        }
197
250
 
 
251
        /// <summary>
 
252
        /// Gets the set up methods.
 
253
        /// </summary>
 
254
        /// <returns></returns>
198
255
        public MethodInfo[] GetSetUpMethods()
199
256
        {
200
257
            return setUpMethods;
201
258
        }
202
259
 
 
260
        /// <summary>
 
261
        /// Gets the tear down methods.
 
262
        /// </summary>
 
263
        /// <returns></returns>
203
264
        public MethodInfo[] GetTearDownMethods()
204
265
        {
205
266
            return tearDownMethods;
207
268
        #endregion
208
269
 
209
270
                #region Test Overrides
 
271
        /// <summary>
 
272
        /// Gets a count of test cases that would be run using
 
273
        /// the specified filter.
 
274
        /// </summary>
 
275
        /// <param name="filter"></param>
 
276
        /// <returns></returns>
210
277
                public override int CountTestCases(TestFilter filter)
211
278
                {
212
279
                        int count = 0;
221
288
                        return count;
222
289
                }
223
290
 
 
291
        /// <summary>
 
292
        /// Runs the suite under a particular filter, sending
 
293
        /// notifications to a listener.
 
294
        /// </summary>
 
295
        /// <param name="listener">An event listener to receive notifications</param>
 
296
        /// <param name="filter">A filter used in running the test</param>
 
297
        /// <returns></returns>
224
298
                public override TestResult Run(ITestListener listener, TestFilter filter)
225
299
                {
226
300
                        using( new TestContext() )
261
335
                        }
262
336
                }
263
337
 
 
338
        /// <summary>
 
339
        /// Runs the suite under a particular filter, sending
 
340
        /// notifications to a listener.
 
341
        /// </summary>
 
342
        /// <param name="suiteResult">The suite result.</param>
 
343
        /// <param name="listener">The listener.</param>
 
344
        /// <param name="filter">The filter.</param>
264
345
        public void Run(TestResult suiteResult, ITestListener listener, TestFilter filter)
265
346
        {
266
347
            suiteResult.Success(); // Assume success
287
368
                #endregion
288
369
 
289
370
                #region Virtual Methods
 
371
        /// <summary>
 
372
        /// Does the one time set up.
 
373
        /// </summary>
 
374
        /// <param name="suiteResult">The suite result.</param>
290
375
        protected virtual void DoOneTimeSetUp(TestResult suiteResult)
291
376
        {
292
377
            if (FixtureType != null)
322
407
                        this.IgnoreReason = ex.Message;
323
408
                    }
324
409
                    else if (ex is NUnit.Framework.AssertionException)
325
 
                        suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.SetUp);
 
410
                        suiteResult.Failure(ex.Message, ex.StackTrace);
326
411
                    else
327
 
                        suiteResult.Error(ex, FailureSite.SetUp);
 
412
                        suiteResult.Error(ex);
328
413
                }
329
414
            }
330
415
        }
331
416
 
 
417
        /// <summary>
 
418
        /// Creates the user fixture.
 
419
        /// </summary>
332
420
                protected virtual void CreateUserFixture()
333
421
                {
334
422
            if (arguments != null && arguments.Length > 0)
337
425
                            Fixture = Reflect.Construct(FixtureType);
338
426
                }
339
427
 
 
428
        /// <summary>
 
429
        /// Does the one time tear down.
 
430
        /// </summary>
 
431
        /// <param name="suiteResult">The suite result.</param>
340
432
        protected virtual void DoOneTimeTearDown(TestResult suiteResult)
341
433
        {
342
434
            if ( this.Fixture != null)
360
452
                catch (Exception ex)
361
453
                {
362
454
                                        // Error in TestFixtureTearDown or Dispose causes the
363
 
                                        // suite to be marked as a failure, even if
 
455
                                        // suite to be marked as a error, even if
364
456
                                        // all the contained tests passed.
365
457
                                        NUnitException nex = ex as NUnitException;
366
458
                                        if (nex != null)
367
459
                                                ex = nex.InnerException;
368
460
 
369
461
 
370
 
                                        suiteResult.Failure(ex.Message, ex.StackTrace, FailureSite.TearDown);
 
462
                                        suiteResult.TearDownError(ex);
371
463
                                }
372
464
 
373
465
                this.Fixture = null;
483
575
                listener.TestStarted(test);
484
576
                TestResult result = new TestResult( test );
485
577
                                string msg = string.Format( "Parent SetUp failed in {0}", this.FixtureType.Name );
486
 
                                result.Failure(msg, null, FailureSite.Parent);
 
578
                                result.Failure(msg, null);
487
579
                MarkTestsFailed(test.Tests, suiteResult, listener, filter);
488
580
                suiteResult.AddResult(result);
489
581
                listener.TestFinished(result);
493
585
                listener.TestStarted(test);
494
586
                TestResult result = new TestResult( test );
495
587
                                string msg = string.Format( "TestFixtureSetUp failed in {0}", this.FixtureType.Name );
496
 
                                result.Failure(msg, null, FailureSite.Parent);
 
588
                                result.Failure(msg, null);
497
589
                                suiteResult.AddResult(result);
498
590
                listener.TestFinished(result);
499
591
            }