recursivetestfilter.cs
来自「NUnit测试工具源码,他使用c#开发的一个测试工具」· CS 代码 · 共 72 行
CS
72 行
using System;
using System.Collections;
using System.Text;
namespace NUnit.Core.Filters
{
/// <summary>
/// RecursiveTestFilter is an abstract base class for filters
/// which pass if either the test itself, a parent test or a
/// descendendant satisfies the criterion for passing.
/// </summary>
[Serializable]
public abstract class RecursiveTestFilter : TestFilter
{
/// <summary>
/// Test the filter on a given test node
/// </summary>
/// <param name="test"></param>
/// <returns></returns>
public override bool Pass(ITest test)
{
if (Match(test))
return true;
if (MatchParent(test))
return true;
if (MatchDescendant(test))
return true;
return false;
}
public abstract bool Match(ITest test);
private bool MatchParent(ITest test)
{
if (test.IsExplicit)
return false;
for (ITest parent = test.Parent; parent != null; parent = parent.Parent)
{
if (Match(parent))
return true;
// Don't proceed past a parent marked Explicit
if (parent.IsExplicit)
return false;
}
return false;
}
private bool MatchDescendant(ITest test)
{
if (!test.IsSuite || test.Tests == null)
return false;
foreach (ITest child in test.Tests)
{
if (Match(child))
return true;
if (MatchDescendant(child))
return true;
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?