PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/ResultSummarizer.cs

#
C# | 193 lines | 130 code | 24 blank | 39 comment | 6 complexity | 15d16e0af6ed83e2ad423e8e78372be5 MD5 | raw file
  1// ****************************************************************
  2// This is free software licensed under the NUnit license. You
  3// may obtain a copy of the license as well as information regarding
  4// copyright ownership at http://nunit.org.
  5// ****************************************************************
  6
  7namespace NUnit.Util
  8{
  9	using System;
 10	using NUnit.Core;
 11
 12	/// <summary>
 13	/// Summary description for ResultSummarizer.
 14	/// </summary>
 15	public class ResultSummarizer
 16	{
 17	    private int resultCount = 0;
 18		private int testsRun = 0;
 19		private int failureCount = 0;
 20	    private int errorCount = 0;
 21	    private int successCount = 0;
 22	    private int inconclusiveCount = 0;
 23		private int skipCount = 0;
 24		private int ignoreCount = 0;
 25	    private int notRunnable = 0;
 26		
 27		private double time = 0.0d;
 28		private string name;
 29
 30		public ResultSummarizer() { }
 31
 32		public ResultSummarizer(TestResult result)
 33		{
 34			Summarize(result);
 35		}
 36
 37		public ResultSummarizer(TestResult[] results)
 38		{
 39			foreach( TestResult result in results )
 40				Summarize(result);
 41		}
 42
 43		public void Summarize( TestResult result )
 44		{
 45			if (this.name == null )
 46			{
 47				this.name = result.Name;
 48				this.time = result.Time;
 49			}
 50
 51			if (!result.Test.IsSuite)
 52			{
 53			    resultCount++;
 54
 55                switch (result.ResultState)
 56                {
 57                    case ResultState.Success:
 58                        successCount++;
 59                        testsRun++;
 60                        break;
 61                    case ResultState.Failure:
 62                        failureCount++;
 63                        testsRun++;
 64                        break;
 65                    case ResultState.Error:
 66                    case ResultState.Cancelled:
 67                        errorCount++;
 68                        testsRun++;
 69                        break;
 70                    case ResultState.Inconclusive:
 71                        inconclusiveCount++;
 72                        testsRun++;
 73                        break;
 74                    case ResultState.NotRunnable:
 75                        notRunnable++;
 76                        //errorCount++;
 77                        break;
 78                    case ResultState.Ignored:
 79                        ignoreCount++;
 80                        break;
 81                    case ResultState.Skipped:
 82                    default:
 83                        skipCount++;
 84                        break;
 85                }
 86            }
 87
 88			if ( result.HasResults )
 89				foreach (TestResult childResult in result.Results)
 90					Summarize( childResult );
 91		}
 92
 93		public string Name
 94		{
 95			get { return name; }
 96		}
 97
 98		public bool Success
 99		{
100			get { return failureCount == 0; }
101		}
102
103        /// <summary>
104        /// Returns the number of test cases for which results
105        /// have been summarized. Any tests excluded by use of
106        /// Category or Explicit attributes are not counted.
107        /// </summary>
108	    public int ResultCount
109	    {
110            get { return resultCount;  }    
111	    }
112
113        /// <summary>
114        /// Returns the number of test cases actually run, which
115        /// is the same as ResultCount, less any Skipped, Ignored
116        /// or NonRunnable tests.
117        /// </summary>
118		public int TestsRun
119		{
120			get { return testsRun; }
121		}
122
123	    /// <summary>
124	    /// Returns the number of tests that passed
125	    /// </summary>
126        public int Passed
127	    {
128            get { return successCount;  }
129	    }
130
131        /// <summary>
132        /// Returns the number of test cases that had an error.
133        /// </summary>
134        public int Errors
135        {
136            get { return errorCount; }
137        }
138
139        /// <summary>
140        /// Returns the number of test cases that failed.
141        /// </summary>
142		public int Failures 
143		{
144			get { return failureCount; }
145		}
146
147        /// <summary>
148        /// Returns the number of test cases that failed.
149        /// </summary>
150        public int Inconclusive
151        {
152            get { return inconclusiveCount; }
153        }
154
155        /// <summary>
156        /// Returns the number of test cases that were not runnable
157        /// due to errors in the signature of the class or method.
158        /// Such tests are also counted as Errors.
159        /// </summary>
160	    public int NotRunnable
161	    {
162	        get { return notRunnable; }   
163	    }
164
165        /// <summary>
166        /// Returns the number of test cases that were skipped.
167        /// </summary>
168		public int Skipped
169		{
170			get { return skipCount; }
171		}
172
173		public int Ignored
174		{
175			get { return ignoreCount; }
176		}
177
178		public double Time
179		{
180			get { return time; }
181		}
182
183		public int TestsNotRun
184		{
185			get { return skipCount + ignoreCount + notRunnable; }
186		}
187
188	    public int ErrorsAndFailures
189	    {
190            get { return errorCount + failureCount; }   
191	    }
192	}
193}