1 // ***********************************************************************
2 // Copyright (c) 2007 Charlie Poole
3 //
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:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
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 // ***********************************************************************
23 
24     using System;
25     using NUnit.Framework;
26     using NUnit.Framework.Api;
27 using NUnit.Framework.Internal;
28 
29 namespace NUnit.TestUtilities
30 {
31     /// <summary>
32     /// Summary description for ResultSummary.
33     /// </summary>
34     public class ResultSummary
35     {
36         private int resultCount = 0;
37         private int testsRun = 0;
38         private int failureCount = 0;
39         private int errorCount = 0;
40         private int successCount = 0;
41         private int inconclusiveCount = 0;
42         private int skipCount = 0;
43         private int ignoreCount = 0;
44         private int notRunnable = 0;
45 
46         private TimeSpan duration = TimeSpan.Zero;
47         private string name;
48 
ResultSummary()49         public ResultSummary() { }
50 
ResultSummary(ITestResult result)51         public ResultSummary(ITestResult result)
52         {
53             Summarize(result);
54         }
55 
Summarize(ITestResult result)56         private void Summarize(ITestResult result)
57         {
58             if (this.name == null)
59             {
60                 this.name = result.Name;
61                 this.duration = result.Duration;
62             }
63 
64             if (result.HasChildren)
65             {
66                 foreach (TestResult childResult in result.Children)
67                     Summarize(childResult);
68             }
69             else
70             {
71                 resultCount++;
72 
73                 switch (result.ResultState.Status)
74                 {
75                     case TestStatus.Passed:
76                         successCount++;
77                         testsRun++;
78                         break;
79                     case TestStatus.Failed:
80                         failureCount++;
81                         testsRun++;
82                         break;
83                     //case TestStatus.Error:
84                     //case TestStatus.Cancelled:
85                     //errorCount++;
86                     //testsRun++;
87                     //break;
88                     case TestStatus.Inconclusive:
89                         inconclusiveCount++;
90                         testsRun++;
91                         break;
92                     //case TestStatus.NotRunnable:
93                     //    notRunnable++;
94                     //    //errorCount++;
95                     //    break;
96                     //case TestStatus.Ignored:
97                     //    ignoreCount++;
98                     //    break;
99                     case TestStatus.Skipped:
100                     default:
101                         skipCount++;
102                         break;
103                 }
104             }
105         }
106 
107         public string Name
108         {
109             get { return name; }
110         }
111 
112         public bool Success
113         {
114             get { return failureCount == 0; }
115         }
116 
117         /// <summary>
118         /// Returns the number of test cases for which results
119         /// have been summarized. Any tests excluded by use of
120         /// Category or Explicit attributes are not counted.
121         /// </summary>
122         public int ResultCount
123         {
124             get { return resultCount; }
125         }
126 
127         /// <summary>
128         /// Returns the number of test cases actually run, which
129         /// is the same as ResultCount, less any Skipped, Ignored
130         /// or NonRunnable tests.
131         /// </summary>
132         public int TestsRun
133         {
134             get { return testsRun; }
135         }
136 
137         /// <summary>
138         /// Returns the number of tests that passed
139         /// </summary>
140         public int Passed
141         {
142             get { return successCount; }
143         }
144 
145         /// <summary>
146         /// Returns the number of test cases that had an error.
147         /// </summary>
148         public int Errors
149         {
150             get { return errorCount; }
151         }
152 
153         /// <summary>
154         /// Returns the number of test cases that failed.
155         /// </summary>
156         public int Failures
157         {
158             get { return failureCount; }
159         }
160 
161         /// <summary>
162         /// Returns the number of test cases that failed.
163         /// </summary>
164         public int Inconclusive
165         {
166             get { return inconclusiveCount; }
167         }
168 
169         /// <summary>
170         /// Returns the number of test cases that were not runnable
171         /// due to errors in the signature of the class or method.
172         /// Such tests are also counted as Errors.
173         /// </summary>
174         public int NotRunnable
175         {
176             get { return notRunnable; }
177         }
178 
179         /// <summary>
180         /// Returns the number of test cases that were skipped.
181         /// </summary>
182         public int Skipped
183         {
184             get { return skipCount; }
185         }
186 
187         public int Ignored
188         {
189             get { return ignoreCount; }
190         }
191 
192         public TimeSpan Duration
193         {
194             get { return duration; }
195         }
196 
197         public int TestsNotRun
198         {
199             get { return skipCount + ignoreCount + notRunnable; }
200         }
201 
202         public int ErrorsAndFailures
203         {
204             get { return errorCount + failureCount; }
205         }
206     }
207 }
208