[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunitlite / ResultSummary.cs
1 // ***********************************************************************
2 // Copyright (c) 2014-2015 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 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using NUnit.Framework.Interfaces;
31
32 namespace NUnitLite
33 {
34     /// <summary>
35     /// Helper class used to summarize the result of a test run
36     /// </summary>
37     public class ResultSummary
38     {
39         #region Constructor
40
41         /// <summary>
42         /// Initializes a new instance of the <see cref="ResultSummary"/> class.
43         /// </summary>
44         /// <param name="result">The result.</param>
45         public ResultSummary(ITestResult result)
46         {
47             InitializeCounters();
48
49             ResultState = result.ResultState;
50             StartTime = result.StartTime;
51             EndTime = result.EndTime;
52             Duration = result.Duration;
53
54             Summarize(result);
55         }
56
57         #endregion
58
59         #region Properties
60
61         /// <summary>
62         /// Gets the number of test cases for which results
63         /// have been summarized. Any tests excluded by use of
64         /// Category or Explicit attributes are not counted.
65         /// </summary>
66         public int TestCount { get; private set; }
67
68         /// <summary>
69         /// Returns the number of test cases actually run.
70         /// </summary>
71         public int RunCount 
72         {
73             get { return PassCount + ErrorCount + FailureCount + InconclusiveCount;  }
74         }
75
76         /// <summary>
77         /// Gets the number of tests not run for any reason.
78         /// </summary>
79         public int NotRunCount
80         {
81             get { return InvalidCount + SkipCount + IgnoreCount + ExplicitCount;  }
82         }
83
84         /// <summary>
85         /// Returns the number of failed test cases (including errors and invalid tests)
86         /// </summary>
87         public int FailedCount
88         {
89             get { return FailureCount + InvalidCount + ErrorCount;  }
90         }
91
92         /// <summary>
93         /// Returns the sum of skipped test cases, including ignored and explicit tests
94         /// </summary>
95         public int TotalSkipCount
96         {
97             get { return SkipCount + IgnoreCount + ExplicitCount;  }
98         }
99
100         /// <summary>
101         /// Gets the count of passed tests
102         /// </summary>
103         public int PassCount { get; private set; }
104
105         /// <summary>
106         /// Gets count of failed tests, excluding errors and invalid tests
107         /// </summary>
108         public int FailureCount { get; private set; }
109
110         /// <summary>
111         /// Gets the error count
112         /// </summary>
113         public int ErrorCount { get; private set; }
114
115         /// <summary>
116         /// Gets the count of inconclusive tests
117         /// </summary>
118         public int InconclusiveCount { get; private set; }
119
120         /// <summary>
121         /// Returns the number of test cases that were not runnable
122         /// due to errors in the signature of the class or method.
123         /// Such tests are also counted as Errors.
124         /// </summary>
125         public int InvalidCount { get; private set; }
126
127         /// <summary>
128         /// Gets the count of skipped tests, excluding ignored tests
129         /// </summary>
130         public int SkipCount { get; private set; }
131
132         /// <summary>
133         /// Gets the ignore count
134         /// </summary>
135         public int IgnoreCount { get; private set; }
136
137         /// <summary>
138         /// Gets the explicit count
139         /// </summary>
140         public int ExplicitCount { get; private set; }
141
142         /// <summary>
143         /// Invalid Test Fixtures
144         /// </summary>
145         public int InvalidTestFixtures { get; private set; }
146
147         /// <summary>
148         /// Gets the ResultState of the test result, which 
149         /// indicates the success or failure of the test.
150         /// </summary>
151         public ResultState ResultState { get; private set; }
152
153         /// <summary>
154         /// Gets or sets the time the test started running.
155         /// </summary>
156         public DateTime StartTime { get; private set; }
157
158         /// <summary>
159         /// Gets or sets the time the test finished running.
160         /// </summary>
161         public DateTime EndTime { get; private set; }
162
163         /// <summary>
164         /// Gets or sets the elapsed time for running the test in seconds
165         /// </summary>
166         public double Duration { get; private set; }
167
168         #endregion
169
170         #region Helper Methods
171
172         private void InitializeCounters()
173         {
174             TestCount = 0;
175             PassCount = 0;
176             FailureCount = 0;
177             ErrorCount = 0;
178             InconclusiveCount = 0;
179             SkipCount = 0;
180             IgnoreCount = 0;
181             ExplicitCount = 0;
182             InvalidCount = 0;
183         }
184
185         private void Summarize(ITestResult result)
186         {
187             var label = result.ResultState.Label;
188             var status = result.ResultState.Status;
189
190             if (result.Test.IsSuite)
191             {
192                 if (status == TestStatus.Failed && label == "Invalid")
193                     InvalidTestFixtures++;
194
195                 foreach (ITestResult r in result.Children)
196                     Summarize(r);
197             }
198             else
199             {
200                 TestCount++;
201                 switch (status)
202                 {
203                     case TestStatus.Passed:
204                         PassCount++;
205                         break;
206                     case TestStatus.Skipped:
207                         if (label == "Ignored")
208                             IgnoreCount++;
209                         else if (label == "Explicit")
210                             ExplicitCount++;
211                         else
212                             SkipCount++;
213                         break;
214                     case TestStatus.Failed:
215                         if (label == "Invalid")
216                             InvalidCount++;
217                         else if (label == "Error")
218                             ErrorCount++;
219                         else
220                             FailureCount++;
221                         break;
222                     case TestStatus.Inconclusive:
223                         InconclusiveCount++;
224                         break;
225                 }
226
227                 return;
228             }
229         }
230
231         #endregion
232     }
233 }