2
// Copyright (C) 2002. James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. All Rights Reserved.
7
using System.Collections;
8
using System.Reflection;
12
/// Summary description for TestSuite.
14
public class TestSuite : Test
16
private ArrayList tests = new ArrayList();
18
public TestSuite(string name) : base(name)
23
protected internal virtual void Add(Test test)
27
test.ShouldRun = ShouldRun;
28
test.IgnoreReason = IgnoreReason;
33
protected internal virtual TestSuite CreateNewSuite(string name)
35
return new TestSuite(name);
38
public void Add(InvalidFixture fixture)
40
TestSuite testSuite = CreateNewSuite(fixture.OriginalType.Name);
42
testSuite.ShouldRun=false;
43
testSuite.IgnoreReason = "Fixture is invalid";
45
MethodInfo [] methods = fixture.OriginalType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic);
46
foreach(MethodInfo method in methods) {
47
TestCase testCase = TestCaseBuilder.Make(fixture, method);
50
testSuite.Add(testCase);
51
testCase.ShouldRun = false;
52
testCase.IgnoreReason = "Fixture is non-runnable";
59
public void Add(object fixture)
61
TestSuite testSuite = CreateNewSuite(fixture.GetType().Name);
64
Type ignoreMethodAttribute = typeof(Nunit.Framework.IgnoreAttribute);
65
object[] attributes = fixture.GetType().GetCustomAttributes(ignoreMethodAttribute, false);
66
if(attributes.Length == 1)
68
IgnoreAttribute attr = (IgnoreAttribute)attributes[0];
69
testSuite.ShouldRun = false;
70
testSuite.IgnoreReason = attr.Reason;
73
MethodInfo [] methods = fixture.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic);
74
foreach(MethodInfo method in methods)
76
TestCase testCase = TestCaseBuilder.Make(fixture, method);
78
testSuite.Add(testCase);
81
if(testSuite.CountTestCases == 0)
83
testSuite.ShouldRun = false;
84
testSuite.IgnoreReason = testSuite.Name + " does not have any tests";
88
public ArrayList Tests
93
public override int CountTestCases
99
foreach(Test test in Tests)
101
count += test.CountTestCases;
107
public override TestResult Run(EventListener listener)
109
TestSuiteResult suiteResult = new TestSuiteResult(this, Name);
111
listener.SuiteStarted(this);
113
suiteResult.Executed = true;
115
long startTime = DateTime.Now.Ticks;
117
RunAllTests(suiteResult,listener);
119
long stopTime = DateTime.Now.Ticks;
121
double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
123
suiteResult.Time = time;
124
if(!ShouldRun) suiteResult.NotRun(this.IgnoreReason);
126
listener.SuiteFinished(suiteResult);
131
protected virtual void RunAllTests(TestSuiteResult suiteResult,EventListener listener)
133
foreach(Test test in Tests)
135
suiteResult.AddResult(test.Run(listener));