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.Collections.Specialized;
31
/// TestInfo holds common info about a test. It represents only
32
/// a single test or a suite and contains no references to other
33
/// tests. Since it is informational only, it can easily be passed
34
/// around using .Net remoting.
36
/// TestInfo is used directly in all EventListener events and in
37
/// TestResults. It contains an ID, which can be used by a
38
/// runner to locate the actual test.
40
/// TestInfo also serves as the base class for TestNode, which
41
/// adds hierarchical information and is used in client code to
42
/// maintain a visible image of the structure of the tests.
45
public class TestInfo : ITest
47
#region Instance Variables
49
/// TestName that identifies this test
51
private TestName testName;
53
private string testType;
55
private RunState runState;
58
/// Reason for not running the test
60
private string ignoreReason;
63
/// Number of test cases in this test or suite
65
private int testCaseCount;
68
/// True if this is a suite
73
/// The test description
75
private string description;
78
/// A list of all the categories assigned to a test
80
private ArrayList categories = new ArrayList();
83
/// A dictionary of properties, used to add information
84
/// to tests without requiring the class to change.
86
private ListDictionary properties = new ListDictionary();
92
/// Construct from an ITest
94
/// <param name="test">Test from which a TestNode is to be constructed</param>
95
public TestInfo( ITest test )
97
this.testName = (TestName)test.TestName.Clone();
98
this.testType = test.TestType;
100
this.runState = test.RunState;
101
this.ignoreReason = test.IgnoreReason;
102
this.description = test.Description;
103
this.isSuite = test.IsSuite;
105
if (test.Categories != null)
106
this.categories.AddRange(test.Categories);
107
if (test.Properties != null)
109
this.properties = new ListDictionary();
110
foreach( DictionaryEntry entry in test.Properties )
111
this.properties.Add( entry.Key, entry.Value );
114
this.testCaseCount = test.TestCount;
118
/// Construct as a parent to multiple tests.
120
/// <param name="testName">The name to use for the new test</param>
121
/// <param name="tests">An array of child tests</param>
122
public TestInfo( TestName testName, ITest[] tests )
124
this.testName = testName;
125
this.testType = "Test Project";
127
this.runState = RunState.Runnable;
128
this.ignoreReason = null;
129
this.description = null;
133
foreach( ITest test in tests )
134
this.testCaseCount += test.TestCount;
138
/// Construct given a test name
140
/// <param name="testName">The TestName for the new test</param>
141
public TestInfo( TestName testName ) : this( testName, null) { }
146
/// Gets the completely specified name of the test
147
/// encapsulated in a TestName object.
149
public TestName TestName
151
get { return testName; }
155
/// Gets a string representing the kind of test this
156
/// object represents for display purposes.
158
public string TestType
160
get { return testType; }
164
/// The test description
166
public string Description
168
get { return description; }
169
set { description = value; }
173
/// Gets the RunState for this test
175
public RunState RunState
177
get { return runState; }
178
set { runState = value; }
182
/// The reason for ignoring a test
184
public string IgnoreReason
186
get { return ignoreReason; }
187
set { ignoreReason = value; }
191
/// Count of test cases in this test.
195
get { return testCaseCount; }
199
/// Gets the parent test of this test
201
public virtual ITest Parent
207
/// Gets a list of the categories applied to this test
209
public IList Categories
211
get { return categories; }
215
/// Gets a list of any child tests
217
public virtual IList Tests
223
/// True if this is a suite, false if a test case
227
get { return isSuite; }
231
/// Gets the Properties dictionary for this test
233
public IDictionary Properties
237
if ( properties == null )
238
properties = new ListDictionary();
247
/// Counts the test cases that would be run if this
248
/// test were executed using the provided filter.
250
/// <param name="filter">The filter to apply</param>
251
/// <returns>A count of test cases</returns>
252
public virtual int CountTestCases(TestFilter filter)
258
return filter.Pass(this) ? 1 : 0;
261
if (filter.Pass(this))
263
foreach (ITest test in Tests)
265
count += test.CountTestCases(filter);