1 // ***********************************************************************
2 // Copyright (c) 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 System.Collections.Generic;
32 using System.Collections.Concurrent;
34 using NUnit.Framework.Interfaces;
35 using System.Threading;
37 using NUnit.Compatibility;
40 namespace NUnit.Framework.Internal
43 /// Represents the result of running a test suite
45 public class TestSuiteResult : TestResult
47 private int _passCount = 0;
48 private int _failCount = 0;
49 private int _skipCount = 0;
50 private int _inconclusiveCount = 0;
52 private ConcurrentQueue<ITestResult> _children;
54 private List<ITestResult> _children;
58 /// Construct a TestSuiteResult base on a TestSuite
60 /// <param name="suite">The TestSuite to which the result applies</param>
61 public TestSuiteResult(TestSuite suite) : base(suite)
64 _children = new ConcurrentQueue<ITestResult>();
66 _children = new List<ITestResult>();
73 /// Gets the number of test cases that failed
74 /// when running the test and all its children.
76 public override int FailCount
81 RwLock.EnterReadLock();
90 RwLock.ExitReadLock();
97 /// Gets the number of test cases that passed
98 /// when running the test and all its children.
100 public override int PassCount
105 RwLock.EnterReadLock();
114 RwLock.ExitReadLock();
121 /// Gets the number of test cases that were skipped
122 /// when running the test and all its children.
124 public override int SkipCount
129 RwLock.EnterReadLock();
138 RwLock.ExitReadLock();
145 /// Gets the number of test cases that were inconclusive
146 /// when running the test and all its children.
148 public override int InconclusiveCount
153 RwLock.EnterReadLock();
157 return _inconclusiveCount;
162 RwLock.ExitReadLock();
169 /// Indicates whether this result has any child results.
171 public override bool HasChildren
176 return !_children.IsEmpty;
178 return _children.Count != 0;
184 /// Gets the collection of child results.
186 public override IEnumerable<ITestResult> Children
188 get { return _children; }
193 #region AddResult Method
196 /// Adds a child result to this result, setting this result's
197 /// ResultState to Failure if the child result failed.
199 /// <param name="result">The result to be added</param>
200 public virtual void AddResult(ITestResult result)
203 var childrenAsConcurrentQueue = Children as ConcurrentQueue<ITestResult>;
204 if (childrenAsConcurrentQueue != null)
205 childrenAsConcurrentQueue.Enqueue(result);
209 var childrenAsIList = Children as IList<ITestResult>;
210 if (childrenAsIList != null)
211 childrenAsIList.Add(result);
213 throw new NotSupportedException("cannot add results to Children");
218 RwLock.EnterWriteLock();
222 // If this result is marked cancelled, don't change it
223 if (ResultState != ResultState.Cancelled)
225 switch (result.ResultState.Status)
227 case TestStatus.Passed:
229 if (ResultState.Status == TestStatus.Inconclusive)
230 SetResult(ResultState.Success);
234 case TestStatus.Failed:
237 if (ResultState.Status != TestStatus.Failed)
238 SetResult(ResultState.ChildFailure, CHILD_ERRORS_MESSAGE);
242 case TestStatus.Skipped:
244 if (result.ResultState.Label == "Ignored")
245 if (ResultState.Status == TestStatus.Inconclusive || ResultState.Status == TestStatus.Passed)
246 SetResult(ResultState.Ignored, CHILD_IGNORE_MESSAGE);
252 InternalAssertCount += result.AssertCount;
253 _passCount += result.PassCount;
254 _failCount += result.FailCount;
255 _skipCount += result.SkipCount;
256 _inconclusiveCount += result.InconclusiveCount;
261 RwLock.ExitWriteLock();