TestSuite
TestSuite represents a composite test, which contains other tests.
using NUnit.Framework.Interfaces;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
namespace NUnit.Framework.Internal
{
public class TestSuite : Test
{
private List<ITest> tests = new List<ITest>();
public override IList<ITest> Tests => tests;
public override int TestCaseCount {
get {
int num = 0;
foreach (Test test in Tests) {
num += test.TestCaseCount;
}
return num;
}
}
public object[] Arguments { get; set; }
protected bool MaintainTestOrder { get; set; }
public override bool HasChildren => tests.Count > 0;
public override string XmlElementName => "test-suite";
public TestSuite(string name)
: base(name)
{
}
public TestSuite(string parentSuiteName, string name)
: base(parentSuiteName, name)
{
}
public TestSuite(Type fixtureType)
: base(fixtureType)
{
string text = base.Name = TypeHelper.GetDisplayName(fixtureType);
string text2 = text;
string namespace = fixtureType.Namespace;
base.FullName = ((namespace != null && namespace != "") ? (namespace + "." + text2) : text2);
}
public void Sort()
{
if (!MaintainTestOrder) {
tests.Sort();
foreach (Test test in Tests) {
(test as TestSuite)?.Sort();
}
}
}
public void Add(Test test)
{
test.Parent = this;
tests.Add(test);
}
public override TestResult MakeTestResult()
{
return new TestSuiteResult(this);
}
public override XmlNode AddToXml(XmlNode parentNode, bool recursive)
{
XmlNode xmlNode = parentNode.AddElement("test-suite");
xmlNode.AddAttribute("type", TestType);
PopulateTestNode(xmlNode, recursive);
xmlNode.AddAttribute("testcasecount", TestCaseCount.ToString());
if (recursive) {
foreach (Test test in Tests) {
test.AddToXml(xmlNode, recursive);
}
return xmlNode;
}
return xmlNode;
}
protected void CheckSetUpTearDownMethods(Type attrType)
{
MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(base.FixtureType, attrType, true);
int num = 0;
MethodInfo methodInfo;
while (true) {
if (num >= methodsWithAttribute.Length)
return;
methodInfo = methodsWithAttribute[num];
if (methodInfo.IsAbstract || (!methodInfo.IsPublic && !methodInfo.IsFamily) || methodInfo.GetParameters().Length != 0 || (methodInfo.ReturnType != typeof(void) && methodInfo.ReturnType != typeof(Task)))
break;
num++;
}
base.Properties.Set("_SKIPREASON", $"""{methodInfo.Name}");
base.RunState = RunState.NotRunnable;
}
}
}