2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / nunit24 / NUnitCore / interfaces / TestInfo.cs
blobb5a480cfc0817d934ead617eb101cd3caf747360
1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
6 using System;
7 using System.Collections;
8 using System.Collections.Specialized;
10 namespace NUnit.Core
12 /// <summary>
13 /// TestInfo holds common info about a test. It represents only
14 /// a single test or a suite and contains no references to other
15 /// tests. Since it is informational only, it can easily be passed
16 /// around using .Net remoting.
17 ///
18 /// TestInfo is used directly in all EventListener events and in
19 /// TestResults. It contains an ID, which can be used by a
20 /// runner to locate the actual test.
21 ///
22 /// TestInfo also serves as the base class for TestNode, which
23 /// adds hierarchical information and is used in client code to
24 /// maintain a visible image of the structure of the tests.
25 /// </summary>
26 [Serializable]
27 public class TestInfo : ITest
29 #region Instance Variables
30 /// <summary>
31 /// TestName that identifies this test
32 /// </summary>
33 private TestName testName;
35 private string testType;
37 private RunState runState;
39 /// <summary>
40 /// Reason for not running the test
41 /// </summary>
42 private string ignoreReason;
44 /// <summary>
45 /// Number of test cases in this test or suite
46 /// </summary>
47 private int testCaseCount;
49 /// <summary>
50 /// True if this is a suite
51 /// </summary>
52 private bool isSuite;
54 /// <summary>
55 /// The test description
56 /// </summary>
57 private string description;
59 /// <summary>
60 /// A list of all the categories assigned to a test
61 /// </summary>
62 private ArrayList categories = new ArrayList();
64 /// <summary>
65 /// A dictionary of properties, used to add information
66 /// to tests without requiring the class to change.
67 /// </summary>
68 private ListDictionary properties = new ListDictionary();
70 #endregion
72 #region Constructors
73 /// <summary>
74 /// Construct from an ITest
75 /// </summary>
76 /// <param name="test">Test from which a TestNode is to be constructed</param>
77 public TestInfo( ITest test )
79 this.testName = (TestName)test.TestName.Clone();
80 this.testType = test.TestType;
82 this.runState = test.RunState;
83 this.ignoreReason = test.IgnoreReason;
84 this.description = test.Description;
85 this.isSuite = test.IsSuite;
87 if (test.Categories != null)
88 this.categories.AddRange(test.Categories);
89 if (test.Properties != null)
91 this.properties = new ListDictionary();
92 foreach( DictionaryEntry entry in test.Properties )
93 this.properties.Add( entry.Key, entry.Value );
96 this.testCaseCount = test.TestCount;
99 /// <summary>
100 /// Construct as a parent to multiple tests.
101 /// </summary>
102 /// <param name="testName">The name to use for the new test</param>
103 /// <param name="tests">An array of child tests</param>
104 public TestInfo( TestName testName, ITest[] tests )
106 this.testName = testName;
107 this.testType = "Test Project";
109 this.runState = RunState.Runnable;
110 this.ignoreReason = null;
111 this.description = null;
112 this.isSuite = true;
114 foreach( ITest test in tests )
116 this.testCaseCount += test.TestCount;
119 #endregion
121 #region Properties
122 /// <summary>
123 /// Gets the completely specified name of the test
124 /// encapsulated in a TestName object.
125 /// </summary>
126 public TestName TestName
128 get { return testName; }
131 /// <summary>
132 /// Gets a string representing the kind of test this
133 /// object represents for display purposes.
134 /// </summary>
135 public string TestType
137 get { return testType; }
140 /// <summary>
141 /// The test description
142 /// </summary>
143 public string Description
145 get { return description; }
146 set { description = value; }
149 /// <summary>
150 /// Gets the RunState for this test
151 /// </summary>
152 public RunState RunState
154 get { return runState; }
155 set { runState = value; }
158 /// <summary>
159 /// The reason for ignoring a test
160 /// </summary>
161 public string IgnoreReason
163 get { return ignoreReason; }
164 set { ignoreReason = value; }
167 /// <summary>
168 /// Count of test cases in this test.
169 /// </summary>
170 public int TestCount
172 get { return testCaseCount; }
175 /// <summary>
176 /// Gets the parent test of this test
177 /// </summary>
178 public virtual ITest Parent
180 get { return null; }
183 /// <summary>
184 /// Gets a list of the categories applied to this test
185 /// </summary>
186 public IList Categories
188 get { return categories; }
191 /// <summary>
192 /// Gets a list of any child tests
193 /// </summary>
194 public virtual IList Tests
196 get { return null; }
199 /// <summary>
200 /// True if this is a suite, false if a test case
201 /// </summary>
202 public bool IsSuite
204 get { return isSuite; }
207 /// <summary>
208 /// Gets the Properties dictionary for this test
209 /// </summary>
210 public IDictionary Properties
212 get
214 if ( properties == null )
215 properties = new ListDictionary();
217 return properties;
220 #endregion
222 #region Methods
223 /// <summary>
224 /// Counts the test cases that would be run if this
225 /// test were executed using the provided filter.
226 /// </summary>
227 /// <param name="filter">The filter to apply</param>
228 /// <returns>A count of test cases</returns>
229 public virtual int CountTestCases(ITestFilter filter)
231 if (filter.IsEmpty)
232 return TestCount;
234 if (!isSuite)
235 return filter.Pass(this) ? 1 : 0;
237 int count = 0;
238 if (filter.Pass(this))
240 foreach (ITest test in Tests)
242 count += test.CountTestCases(filter);
245 return count;
247 #endregion