1 // ***********************************************************************
2 // Copyright (c) 2014-2015 Charlie Poole
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
30 using NUnit.Framework.Interfaces;
35 /// Helper class used to summarize the result of a test run
37 public class ResultSummary
42 /// Initializes a new instance of the <see cref="ResultSummary"/> class.
44 /// <param name="result">The result.</param>
45 public ResultSummary(ITestResult result)
49 ResultState = result.ResultState;
50 StartTime = result.StartTime;
51 EndTime = result.EndTime;
52 Duration = result.Duration;
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.
66 public int TestCount { get; private set; }
69 /// Returns the number of test cases actually run.
73 get { return PassCount + ErrorCount + FailureCount + InconclusiveCount; }
77 /// Gets the number of tests not run for any reason.
79 public int NotRunCount
81 get { return InvalidCount + SkipCount + IgnoreCount + ExplicitCount; }
85 /// Returns the number of failed test cases (including errors and invalid tests)
87 public int FailedCount
89 get { return FailureCount + InvalidCount + ErrorCount; }
93 /// Returns the sum of skipped test cases, including ignored and explicit tests
95 public int TotalSkipCount
97 get { return SkipCount + IgnoreCount + ExplicitCount; }
101 /// Gets the count of passed tests
103 public int PassCount { get; private set; }
106 /// Gets count of failed tests, excluding errors and invalid tests
108 public int FailureCount { get; private set; }
111 /// Gets the error count
113 public int ErrorCount { get; private set; }
116 /// Gets the count of inconclusive tests
118 public int InconclusiveCount { get; private set; }
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.
125 public int InvalidCount { get; private set; }
128 /// Gets the count of skipped tests, excluding ignored tests
130 public int SkipCount { get; private set; }
133 /// Gets the ignore count
135 public int IgnoreCount { get; private set; }
138 /// Gets the explicit count
140 public int ExplicitCount { get; private set; }
143 /// Invalid Test Fixtures
145 public int InvalidTestFixtures { get; private set; }
148 /// Gets the ResultState of the test result, which
149 /// indicates the success or failure of the test.
151 public ResultState ResultState { get; private set; }
154 /// Gets or sets the time the test started running.
156 public DateTime StartTime { get; private set; }
159 /// Gets or sets the time the test finished running.
161 public DateTime EndTime { get; private set; }
164 /// Gets or sets the elapsed time for running the test in seconds
166 public double Duration { get; private set; }
170 #region Helper Methods
172 private void InitializeCounters()
178 InconclusiveCount = 0;
185 private void Summarize(ITestResult result)
187 var label = result.ResultState.Label;
188 var status = result.ResultState.Status;
190 if (result.Test.IsSuite)
192 if (status == TestStatus.Failed && label == "Invalid")
193 InvalidTestFixtures++;
195 foreach (ITestResult r in result.Children)
203 case TestStatus.Passed:
206 case TestStatus.Skipped:
207 if (label == "Ignored")
209 else if (label == "Explicit")
214 case TestStatus.Failed:
215 if (label == "Invalid")
217 else if (label == "Error")
222 case TestStatus.Inconclusive: