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 // ****************************************************************
7 using System
.Collections
;
8 using System
.Collections
.Specialized
;
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.
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.
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.
27 public class TestInfo
: ITest
29 #region Instance Variables
31 /// TestName that identifies this test
33 private TestName testName
;
35 private string testType
;
37 private RunState runState
;
40 /// Reason for not running the test
42 private string ignoreReason
;
45 /// Number of test cases in this test or suite
47 private int testCaseCount
;
50 /// True if this is a suite
55 /// The test description
57 private string description
;
60 /// A list of all the categories assigned to a test
62 private ArrayList categories
= new ArrayList();
65 /// A dictionary of properties, used to add information
66 /// to tests without requiring the class to change.
68 private ListDictionary properties
= new ListDictionary();
74 /// Construct from an ITest
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
;
100 /// Construct as a parent to multiple tests.
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;
114 foreach( ITest test
in tests
)
116 this.testCaseCount
+= test
.TestCount
;
123 /// Gets the completely specified name of the test
124 /// encapsulated in a TestName object.
126 public TestName TestName
128 get { return testName; }
132 /// Gets a string representing the kind of test this
133 /// object represents for display purposes.
135 public string TestType
137 get { return testType; }
141 /// The test description
143 public string Description
145 get { return description; }
146 set { description = value; }
150 /// Gets the RunState for this test
152 public RunState RunState
154 get { return runState; }
155 set { runState = value; }
159 /// The reason for ignoring a test
161 public string IgnoreReason
163 get { return ignoreReason; }
164 set { ignoreReason = value; }
168 /// Count of test cases in this test.
172 get { return testCaseCount; }
176 /// Gets the parent test of this test
178 public virtual ITest Parent
184 /// Gets a list of the categories applied to this test
186 public IList Categories
188 get { return categories; }
192 /// Gets a list of any child tests
194 public virtual IList Tests
200 /// True if this is a suite, false if a test case
204 get { return isSuite; }
208 /// Gets the Properties dictionary for this test
210 public IDictionary Properties
214 if ( properties
== null )
215 properties
= new ListDictionary();
224 /// Counts the test cases that would be run if this
225 /// test were executed using the provided filter.
227 /// <param name="filter">The filter to apply</param>
228 /// <returns>A count of test cases</returns>
229 public virtual int CountTestCases(ITestFilter filter
)
235 return filter
.Pass(this) ? 1 : 0;
238 if (filter
.Pass(this))
240 foreach (ITest test
in Tests
)
242 count
+= test
.CountTestCases(filter
);