Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/extension/NUnit2FrameworkDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public string Explore(string filter)
if (Runner.Test == null)
return String.Format(LOAD_RESULT_FORMAT, TestID, _name, _fullname, "Error loading test");

return Runner.Test.ToXml(true).OuterXml;
ITestFilter v2Filter = CreateNUnit2TestFilter(filter);

return Runner.Test.ToXml(v2Filter).OuterXml;
}

public void StopRun(bool force)
Expand Down
29 changes: 28 additions & 1 deletion src/extension/XmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public static XmlNode ToXml(this ITest test, bool recursive)
return topNode.FirstChild;
}

/// <summary>
/// Returns an XmlNode representing a test recursively, applying a filter
/// </summary>
public static XmlNode ToXml(this ITest test, ITestFilter filter)
{
var doc = new XmlDocument();
doc.LoadXml("<dummy/>");
var topNode = doc.FirstChild;

topNode.AddTest(test, filter);

return topNode.FirstChild;
}

#endregion

#region TestResult Extensions
Expand All @@ -89,7 +103,7 @@ public static XmlNode ToXml(this TestResult result, bool recursive)

#region XmlNode Extensions

// Adds a test-suite or test-case element, without result info
// Adds a test-suite or test-case element recursively, applying a filter
private static XmlNode AddTest(this XmlNode parent, ITest test, bool recursive)
{
var thisNode = parent.AddElement(test.IsSuite ? "test-suite" : "test-case");
Expand Down Expand Up @@ -126,6 +140,19 @@ private static XmlNode AddTest(this XmlNode parent, ITest test, bool recursive)
return thisNode;
}

// Adds a test-suite or test-case element, without result info
private static XmlNode AddTest(this XmlNode parent, ITest test, ITestFilter filter)
{
var thisNode = parent.AddTest(test, false);

if (test.IsSuite)
foreach (ITest child in test.Tests)
if (filter.Pass(child))
thisNode.AddTest(child, filter);

return thisNode;
}

// Adds a test-suite or test-case element, with result info
private static void AddResult(this XmlNode parent, TestResult result, bool recursive)
{
Expand Down
21 changes: 14 additions & 7 deletions src/nunit.v2.driver.tests/NUnit2FrameworkDriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class NUnit2FrameworkDriverTests
private const string V2_DOMAIN_NAME = "v2_test_domain";
private const string EMPTY_FILTER = "<filter/>";
private const int TESTCASECOUNT = 76;
private const int EXPLICITTESTS = 1;
private const int EXPLICIT_TESTS = 1;
private const int EXPLICITFILTERING_CATEGORY = 2;

private static readonly string V2_TEST_PATH = Path.Combine(TestContext.CurrentContext.TestDirectory, V2_TEST_DIR);
private static readonly string ASSEMBLY_PATH = Path.Combine(V2_TEST_PATH, ASSEMBLY_NAME);
Expand All @@ -53,23 +54,29 @@ public void CreateDriver()
PerformBasicResultChecks(_driver.Load(ASSEMBLY_PATH, settings));
}

[Test]
public void Explore()
[TestCase("<filter><cat>ExplicitFiltering</cat></filter>", EXPLICITFILTERING_CATEGORY)]
[TestCase("<filter><not><not><cat>ExplicitFiltering</cat></not></not></filter>", EXPLICIT_TESTS)]
// Running this case last demonstrates that the loaded test is not changed
// as a result of the filtering in the firt tests.
[TestCase(EMPTY_FILTER, TESTCASECOUNT - EXPLICIT_TESTS)]
public void Explore(string filter, int expectedCount)
{
PerformBasicResultChecks(_driver.Explore(EMPTY_FILTER));
XmlNode result = GetResult(_driver.Explore(filter));
PerformBasicResultChecks(_driver.Explore(filter));
Assert.That(result.SelectNodes("//test-case").Count, Is.EqualTo(expectedCount));
}

[Test]
public void CountTestCases()
{
Assert.That(_driver.CountTestCases(EMPTY_FILTER), Is.EqualTo(TESTCASECOUNT -EXPLICITTESTS));
Assert.That(_driver.CountTestCases(EMPTY_FILTER), Is.EqualTo(TESTCASECOUNT -EXPLICIT_TESTS));
}

[Test]
public void ExplicitTestsAreExcluded()
{
var filter = "<filter><not><not><cat>ExplicitFiltering</cat></not></not></filter>";
Assert.That(_driver.CountTestCases(filter), Is.EqualTo(EXPLICITTESTS));
Assert.That(_driver.CountTestCases(filter), Is.EqualTo(EXPLICIT_TESTS));
}

[Test]
Expand All @@ -84,7 +91,7 @@ public void Run()
{
XmlNode result = GetResult(_driver.Run(null, EMPTY_FILTER));
PerformBasicResultChecks(result);
Assert.That(result.SelectNodes("//test-case").Count, Is.EqualTo(TESTCASECOUNT-EXPLICITTESTS));
Assert.That(result.SelectNodes("//test-case").Count, Is.EqualTo(TESTCASECOUNT-EXPLICIT_TESTS));
}

private XmlNode GetResult(string xml)
Expand Down