/src/NUnit/interfaces/TestNode.cs
C# | 88 lines | 43 code | 7 blank | 38 comment | 1 complexity | 29b4a3d4bd69e8a438ddf0022da56f83 MD5 | raw file
1// **************************************************************** 2// Copyright 2007, Charlie Poole 3// This is free software licensed under the NUnit license. You may 4// obtain a copy of the license at http://nunit.org 5// **************************************************************** 6using System; 7using System.Collections; 8 9namespace NUnit.Core 10{ 11 /// <summary> 12 /// TestNode represents a single test or suite in the test hierarchy. 13 /// TestNode holds common info needed about a test and represents a 14 /// single node - either a test or a suite - in the hierarchy of tests. 15 /// 16 /// TestNode extends TestInfo, which holds all the information with 17 /// the exception of the list of child classes. When constructed from 18 /// a Test, TestNodes are always fully populated with child TestNodes. 19 /// 20 /// Like TestInfo, TestNode is purely a data class, and is not able 21 /// to execute tests. 22 /// 23 /// </summary> 24 [Serializable] 25 public class TestNode : TestInfo 26 { 27 #region Instance Variables 28 private ITest parent; 29 30 /// <summary> 31 /// For a test suite, the child tests or suites 32 /// Null if this is not a test suite 33 /// </summary> 34 private ArrayList tests; 35 #endregion 36 37 #region Constructors 38 /// <summary> 39 /// Construct from an ITest 40 /// </summary> 41 /// <param name="test">Test from which a TestNode is to be constructed</param> 42 public TestNode ( ITest test ) : base( test ) 43 { 44 if ( test.IsSuite ) 45 { 46 this.tests = new ArrayList(); 47 48 foreach( ITest child in test.Tests ) 49 { 50 TestNode node = new TestNode( child ); 51 this.Tests.Add( node ); 52 node.parent = this; 53 } 54 } 55 } 56 57 /// <summary> 58 /// Construct a TestNode given a TestName and an 59 /// array of child tests. 60 /// </summary> 61 /// <param name="testName">The TestName of the new test</param> 62 /// <param name="tests">An array of tests to be added as children of the new test</param> 63 public TestNode ( TestName testName, ITest[] tests ) : base( testName, tests ) 64 { 65 this.tests = new ArrayList(); 66 this.tests.AddRange( tests ); 67 } 68 #endregion 69 70 #region Properties 71 /// <summary> 72 /// Gets the parent test of the current test 73 /// </summary> 74 public override ITest Parent 75 { 76 get { return parent; } 77 } 78 79 /// <summary> 80 /// Array of child tests, null if this is a test case. 81 /// </summary> 82 public override IList Tests 83 { 84 get { return tests; } 85 } 86 #endregion 87 } 88}