1
+ /*
2
+ Should hold n TestCase's, run them and do a single report for all.
3
+ */
4
+
5
+ import leanUnit.*
6
+
7
+ class leanUnit .TestSuite
8
+ {
9
+ var testCases: Array
10
+
11
+ var testCount: Number = 0
12
+ var assertionCount: Number = 0
13
+ var failures: Array = new Array ()
14
+
15
+ //-------------------------------------------------------------------
16
+ // CONSTRUCTOR
17
+ //-------------------------------------------------------------------
18
+
19
+ function TestSuite()
20
+ {
21
+ testCases = new Array ()
22
+ }
23
+
24
+
25
+ //-------------------------------------------------------------------
26
+ // PUBLIC FUNCTIONS
27
+ //-------------------------------------------------------------------
28
+
29
+ function addCase( testCase: TestCase )
30
+ {
31
+ testCases. push ( testCase )
32
+ }
33
+
34
+ function run()
35
+ {
36
+ reset ()
37
+
38
+ Output. writeln( "Running " + testCases. join (', ' ) )
39
+
40
+ var startTime = getTimer()
41
+ for ( var i= 0 ; i< testCases. length ; i++ )
42
+ {
43
+ var testCase: TestCase = testCases[ i]
44
+ testCase. run( true )
45
+
46
+ failures = merge ( failures, testCase. failures )
47
+ testCount += testCase. testMethods. length
48
+ assertionCount += testCase. assertionCount
49
+ }
50
+ var endTime = getTimer() - startTime
51
+
52
+ Output. writeln()
53
+ Output. writeln('Finished in ' + (endTime/ 1000 )+ ' seconds' )
54
+
55
+ report()
56
+ }
57
+
58
+ //-------------------------------------------------------------------
59
+ // PRIVATE FUNCTIONS
60
+ //-------------------------------------------------------------------
61
+
62
+ private function reset ()
63
+ {
64
+ testCount = 0
65
+ assertionCount = 0
66
+ failures = new Array ()
67
+ }
68
+
69
+ private function merge ( array :Array , array2 :Array )
70
+ {
71
+ for ( var i= 0 ; i< array2. length ; i++ )
72
+ {
73
+ array. push (array2[ i] )
74
+ }
75
+ return array
76
+ }
77
+
78
+ private function report ()
79
+ {
80
+ for ( var i= 0 ; i< failures. length ; i++ )
81
+ {
82
+ Output. writeln()
83
+ Output. writeln( (i+ 1 )+ ")" )
84
+ Output. writeln( failures[ i] , "fail" )
85
+ }
86
+ Output. writeln()
87
+ Output. writeln( testCount+ " tests, " + assertionCount+ " assertions, " + failures. length + " failures" , failures. length > 0 ? 'fail' : 'success' )
88
+ }
89
+
90
+ }
0 commit comments