1
// ***********************************************************************
2
// Copyright (c) 2007 Charlie Poole
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the
6
// "Software"), to deal in the Software without restriction, including
7
// without limitation the rights to use, copy, modify, merge, publish,
8
// distribute, sublicense, and/or sell copies of the Software, and to
9
// permit persons to whom the Software is furnished to do so, subject to
10
// the following conditions:
12
// The above copyright notice and this permission notice shall be
13
// included in all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
// ***********************************************************************
25
using System.Collections;
26
using System.Reflection;
27
using NUnit.Framework;
32
/// TestSuite represents a collection of tests
34
public class TestSuite : ITest
36
#region Instance Variables
38
private string fullName;
40
private RunState runState = RunState.Runnable;
41
private string ignoreReason;
43
private IDictionary properties = new Hashtable();
45
private NUnit.ObjectList tests = new NUnit.ObjectList();
50
/// Initializes a new instance of the <see cref="TestSuite"/> class.
52
/// <param name="name">The name of the suite.</param>
53
public TestSuite(string name)
59
/// Initializes a new instance of the <see cref="TestSuite"/> class.
61
/// <param name="type">The type used to create the suite.</param>
62
public TestSuite(Type type)
64
this.name = type.Name;
65
this.fullName = type.FullName;
71
/// Gets the name of the suite.
73
/// <value>The name.</value>
80
/// Gets the full name of the suite.
82
/// <value>The full name.</value>
83
public string FullName
85
get { return fullName; }
89
/// Gets or sets the run state of the suite.
91
/// <value>The run state.</value>
92
public RunState RunState
94
get { return runState; }
95
set { runState = value; }
99
/// Gets or sets the ignore reason.
101
/// <value>The ignore reason.</value>
102
public string IgnoreReason
104
get { return ignoreReason; }
105
set { ignoreReason = value; }
109
/// Gets the properties collection for this suite.
111
/// <value>The properties.</value>
112
public IDictionary Properties
114
get { return properties; }
118
/// Gets the test case count.
120
/// <value>The test case count.</value>
121
public int TestCaseCount
126
foreach (ITest test in this.tests)
127
count += test.TestCaseCount;
135
/// <value>The tests.</value>
138
get { return tests; }
142
#region Public Methods
146
/// <returns>A TestResult</returns>
147
public TestResult Run()
149
return Run(new NullListener());
155
/// <param name="listener">A TestListener to handle test events</param>
156
/// <returns>A TestResult</returns>
157
public TestResult Run(TestListener listener)
159
int count = 0, failures = 0, errors = 0;
160
listener.TestStarted(this);
161
TestResult result = new TestResult(this);
163
switch (this.RunState)
165
case RunState.NotRunnable:
166
result.Error(this.IgnoreReason);
169
case RunState.Ignored:
170
result.NotRun(this.IgnoreReason);
173
case RunState.Runnable:
174
foreach (ITest test in tests)
177
TestResult r = test.Run(listener);
179
switch (r.ResultState)
181
case ResultState.Error:
184
case ResultState.Failure:
193
result.NotRun("Class has no tests");
194
else if (errors > 0 || failures > 0)
195
result.Failure("One or more component tests failed");
201
listener.TestFinished(result);
208
/// <param name="test">The test.</param>
209
public void AddTest(ITest test)