Browse Source

Added a namespace filter command line option to nunit-console.exe which can be used to run only those tests in a particular namespace. This filtering is used when the user selects a namespace node in the Unit Tests tree and runs the tests.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2076 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
e11ef3bdba
  1. 5
      src/AddIns/Misc/UnitTesting/Src/ITestTreeView.cs
  2. 13
      src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs
  3. 11
      src/AddIns/Misc/UnitTesting/Src/TestNamespaceTreeNode.cs
  4. 18
      src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
  5. 12
      src/AddIns/Misc/UnitTesting/Src/TestableCondition.cs
  6. 26
      src/AddIns/Misc/UnitTesting/Src/UnitTestApplicationStartHelper.cs
  7. 117
      src/AddIns/Misc/UnitTesting/Test/NamespaceFilterTests.cs
  8. 17
      src/AddIns/Misc/UnitTesting/Test/TestableConditionTests.cs
  9. 35
      src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs
  10. 11
      src/AddIns/Misc/UnitTesting/Test/UnitTestCommandLineTests.cs
  11. 10
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  12. 23
      src/AddIns/Misc/UnitTesting/Test/Utils/MockTestCase.cs
  13. 10
      src/AddIns/Misc/UnitTesting/Test/Utils/MockTestTreeView.cs

5
src/AddIns/Misc/UnitTesting/Src/ITestTreeView.cs

@ -28,5 +28,10 @@ namespace ICSharpCode.UnitTesting @@ -28,5 +28,10 @@ namespace ICSharpCode.UnitTesting
/// in the test tree view.
/// </summary>
IProject SelectedProject {get;}
/// <summary>
/// Gets the namespace for the selected namespace node.
/// </summary>
string SelectedNamespace {get;}
}
}

13
src/AddIns/Misc/UnitTesting/Src/RunTestCommands.cs

@ -61,6 +61,7 @@ namespace ICSharpCode.UnitTesting @@ -61,6 +61,7 @@ namespace ICSharpCode.UnitTesting
IMember m = TestableCondition.GetMember(Owner);
IClass c = (m != null) ? m.DeclaringType : TestableCondition.GetClass(Owner);
IProject project = TestableCondition.GetProject(Owner);
string namespaceFilter = TestableCondition.GetNamespace(Owner);
if (project != null) {
projects.Add(project);
@ -74,7 +75,7 @@ namespace ICSharpCode.UnitTesting @@ -74,7 +75,7 @@ namespace ICSharpCode.UnitTesting
BeforeRun();
if (IsRunningTest) {
currentProject = projects[0];
Run(currentProject, c, m);
Run(currentProject, namespaceFilter, c, m);
}
} catch {
runningTestCommand = null;
@ -132,7 +133,7 @@ namespace ICSharpCode.UnitTesting @@ -132,7 +133,7 @@ namespace ICSharpCode.UnitTesting
projects.Remove(currentProject);
if (projects.Count > 0) {
currentProject = projects[0];
Run(currentProject, null, null);
Run(currentProject, null, null, null);
} else {
runningTestCommand = null;
UpdateUnitTestsPadToolbar();
@ -163,11 +164,11 @@ namespace ICSharpCode.UnitTesting @@ -163,11 +164,11 @@ namespace ICSharpCode.UnitTesting
/// <summary>
/// Runs the tests after building the project under test.
/// </summary>
void Run(IProject project, IClass fixture, IMember test)
void Run(IProject project, string namespaceFilter, IClass fixture, IMember test)
{
BuildProjectBeforeTestRun build = new BuildProjectBeforeTestRun(project);
build.BuildComplete += delegate {
OnBuildComplete(build.LastBuildResults, project, fixture, test);
OnBuildComplete(build.LastBuildResults, project, namespaceFilter, fixture, test);
};
build.Run();
}
@ -277,11 +278,11 @@ namespace ICSharpCode.UnitTesting @@ -277,11 +278,11 @@ namespace ICSharpCode.UnitTesting
/// <summary>
/// Runs the test for the project after a successful build.
/// </summary>
void OnBuildComplete(BuildResults results, IProject project, IClass fixture, IMember test)
void OnBuildComplete(BuildResults results, IProject project, string namespaceFilter, IClass fixture, IMember test)
{
if (results.ErrorCount == 0 && IsRunningTest) {
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, fixture, test);
helper.Initialize(project, namespaceFilter, fixture, test);
helper.Results = Path.GetTempFileName();
ResetTestResults(project);

11
src/AddIns/Misc/UnitTesting/Src/TestNamespaceTreeNode.cs

@ -115,6 +115,17 @@ namespace ICSharpCode.UnitTesting @@ -115,6 +115,17 @@ namespace ICSharpCode.UnitTesting
}
}
}
/// <summary>
/// Gets the full namespace of this tree node. This includes any
/// parent namespaces prefixed to the namespace associated
/// with this tree node.
/// </summary>
public string FullNamespace {
get {
return fullNamespace;
}
}
/// <summary>
/// Adds the test class nodes for this namespace when the

18
src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs

@ -173,6 +173,24 @@ namespace ICSharpCode.UnitTesting @@ -173,6 +173,24 @@ namespace ICSharpCode.UnitTesting
}
}
/// <summary>
/// If a namespace node is selected then the fully qualified namespace
/// for this node is returned (i.e. includes the parent namespace prefixed
/// to it). For all other nodes this returns null.
/// </summary>
public string SelectedNamespace {
get {
TestNamespaceTreeNode selectedNode = SelectedNode as TestNamespaceTreeNode;
if (selectedNode != null) {
return selectedNode.FullNamespace;
}
return null;
}
}
/// <summary>
/// Gets the selected test project.
/// </summary>
public TestProject SelectedTestProject {
get {
TestTreeNode selectedNode = SelectedNode as TestTreeNode;

12
src/AddIns/Misc/UnitTesting/Src/TestableCondition.cs

@ -69,6 +69,18 @@ namespace ICSharpCode.UnitTesting @@ -69,6 +69,18 @@ namespace ICSharpCode.UnitTesting
return null;
}
/// <summary>
/// Returns the namespace selected if any.
/// </summary>
public static string GetNamespace(object caller)
{
ITestTreeView testTreeView = caller as ITestTreeView;
if (testTreeView != null) {
return testTreeView.SelectedNamespace;
}
return null;
}
public bool IsValid(object caller, Condition condition)
{
IMember m = GetMember(caller);

26
src/AddIns/Misc/UnitTesting/Src/UnitTestApplicationStartHelper.cs

@ -78,12 +78,31 @@ namespace ICSharpCode.UnitTesting @@ -78,12 +78,31 @@ namespace ICSharpCode.UnitTesting
/// </summary>
public string Results;
IProject project;
/// <summary>
/// The namespace that tests need to be a part of if they are to
/// be run.
/// </summary>
public string NamespaceFilter;
IProject project;
public void Initialize(IProject project, IClass fixture, IMember test)
{
Initialize(project, null, fixture, test);
}
public void Initialize(IProject project, string namespaceFilter)
{
Initialize(project, namespaceFilter, null, null);
}
public void Initialize(IProject project, string namespaceFilter, IClass fixture, IMember test)
{
this.project = project;
Assemblies.Add(project.OutputAssemblyFullPath);
if (namespaceFilter != null) {
NamespaceFilter = namespaceFilter;
}
if (fixture != null) {
Fixture = fixture.FullyQualifiedName;
if (test != null) {
@ -137,6 +156,11 @@ namespace ICSharpCode.UnitTesting @@ -137,6 +156,11 @@ namespace ICSharpCode.UnitTesting
b.Append(Results);
b.Append('"');
}
if (NamespaceFilter != null) {
b.Append(" /namespaceFilter=\"");
b.Append(NamespaceFilter);
b.Append('"');
}
if (Fixture != null) {
b.Append(" /fixture=\"");
b.Append(Fixture);

117
src/AddIns/Misc/UnitTesting/Test/NamespaceFilterTests.cs

@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using NUnit.ConsoleRunner;
using NUnit.Core;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests
{
/// <summary>
/// Tests the NamespaceFilter class that is a part of SharpDevelop's
/// customised nunit-console.exe.
/// </summary>
[TestFixture]
public class NamespaceFilterTests
{
[Test]
public void TestCaseExcluded()
{
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
MockTestCase testCase = new MockTestCase("Project.NotTests.MyTest");
Assert.IsFalse(filter.Pass(testCase));
}
[Test]
public void TestCaseIncluded()
{
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
MockTestCase testCase = new MockTestCase("Project.Tests.MyTest");
Assert.IsTrue(filter.Pass(testCase));
}
[Test]
public void NullTestCase()
{
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
MockTestCase testCase = null;
Assert.IsFalse(filter.Pass(testCase));
}
[Test]
public void TestCaseNameMatchesNamespace()
{
NamespaceFilter filter = new NamespaceFilter("Project.Test");
MockTestCase testCase = new MockTestCase("Project.Test");
Assert.IsFalse(filter.Pass(testCase));
}
[Test]
public void NullTestSuite()
{
NamespaceSuite testSuite = null;
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
Assert.IsFalse(filter.Pass(testSuite));
}
[Test]
public void NamespaceTestSuiteIncluded()
{
NamespaceSuite testSuite = new NamespaceSuite("Project", "Tests", 0);
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
Assert.IsTrue(filter.Pass(testSuite));
}
[Test]
public void RootNamespaceTestSuiteIncluded()
{
NamespaceSuite testSuite = new NamespaceSuite("Project", 0);
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
Assert.IsTrue(filter.Pass(testSuite));
}
[Test]
public void ChildNamespaceTestSuiteIncluded()
{
NamespaceSuite testSuite = new NamespaceSuite("Project", "Tests", 0);
NamespaceFilter filter = new NamespaceFilter("Project");
Assert.IsTrue(filter.Pass(testSuite));
}
[Test]
public void NamespaceTestSuiteExcluded()
{
NamespaceSuite testSuite = new NamespaceSuite("Project", "Different", 0);
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
Assert.IsFalse(filter.Pass(testSuite));
}
[Test]
public void RootNamespaceTestSuiteExcluded()
{
NamespaceSuite testSuite = new NamespaceSuite("Root", 0);
NamespaceFilter filter = new NamespaceFilter("Project.Tests");
Assert.IsFalse(filter.Pass(testSuite));
}
[Test]
public void TestSuitePasses()
{
TestSuite testSuite = new TestSuite("TestSuite");
NamespaceFilter filter = new NamespaceFilter("Tests");
Assert.IsTrue(filter.Pass(testSuite));
}
[Test]
public void NamespaceFilterClassIsSerializable()
{
Assert.IsTrue(typeof(NamespaceFilter).IsSerializable);
}
}
}

17
src/AddIns/Misc/UnitTesting/Test/TestableConditionTests.cs

@ -43,6 +43,12 @@ namespace UnitTesting.Tests @@ -43,6 +43,12 @@ namespace UnitTesting.Tests
Assert.IsNull(TestableCondition.GetProject(null));
}
[Test]
public void GetNamespaceFromNullOwner()
{
Assert.IsNull(TestableCondition.GetNamespace(null));
}
[Test]
public void IsValidFromNullOwner()
{
@ -80,6 +86,17 @@ namespace UnitTesting.Tests @@ -80,6 +86,17 @@ namespace UnitTesting.Tests
Assert.IsTrue(Object.ReferenceEquals(project, TestableCondition.GetProject(mockTreeView)));
}
[Test]
public void GetNamespaceFromTreeView()
{
MockTestTreeView mockTreeView = new MockTestTreeView();
MSBuildBasedProject project = new MockCSharpProject();
mockTreeView.SelectedProject = project;
mockTreeView.SelectedNamespace = "MyProject.Tests";
Assert.AreEqual("MyProject.Tests", TestableCondition.GetNamespace(mockTreeView));
}
[Test]
public void GetMemberFromMemberNode()
{

35
src/AddIns/Misc/UnitTesting/Test/Tree/OneTestClassTestFixture.cs

@ -144,6 +144,27 @@ namespace UnitTesting.Tests.Tree @@ -144,6 +144,27 @@ namespace UnitTesting.Tests.Tree
Assert.IsNull(treeView.SelectedProject);
}
[Test]
public void SelectedNamespaceWhenNoNodeSelected()
{
treeView.SelectedNode = null;
Assert.IsNull(treeView.SelectedNamespace);
}
[Test]
public void SelectedRootNamespaceNode()
{
treeView.SelectedNode = rootNamespaceNode;
Assert.AreEqual("RootNamespace", treeView.SelectedNamespace);
}
[Test]
public void SelectedTestsNamespaceNode()
{
treeView.SelectedNode = testsNamespaceNode;
Assert.AreEqual("RootNamespace.Tests", treeView.SelectedNamespace);
}
[Test]
public void SelectedProject()
{
@ -181,6 +202,13 @@ namespace UnitTesting.Tests.Tree @@ -181,6 +202,13 @@ namespace UnitTesting.Tests.Tree
Assert.AreEqual("RootNamespace", rootNamespaceNode.Text);
}
[Test]
public void RootNamespaceNodeFullNamespace()
{
TestNamespaceTreeNode node = (TestNamespaceTreeNode)rootNamespaceNode;
Assert.AreEqual("RootNamespace", node.FullNamespace);
}
[Test]
public void RootNamespaceNodeIsTestNamespaceNode()
{
@ -199,6 +227,13 @@ namespace UnitTesting.Tests.Tree @@ -199,6 +227,13 @@ namespace UnitTesting.Tests.Tree
Assert.AreEqual("Tests", testsNamespaceNode.Text);
}
[Test]
public void TestsNamespaceNodeFullNamespace()
{
TestNamespaceTreeNode node = (TestNamespaceTreeNode)testsNamespaceNode;
Assert.AreEqual("RootNamespace.Tests", node.FullNamespace);
}
[Test]
public void TestsNamespaceNodeIsNamespaceNode()
{

11
src/AddIns/Misc/UnitTesting/Test/UnitTestCommandLineTests.cs

@ -126,6 +126,17 @@ namespace UnitTesting.Tests @@ -126,6 +126,17 @@ namespace UnitTesting.Tests
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
}
[Test]
public void TestNamespaceSpecifiedInInitialize()
{
helper.Initialize(project, "Project.MyTests");
helper.NoLogo = false;
helper.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /namespaceFilter=\"Project.MyTests\"";
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
}
[Test]
public void FullCommandLine()
{

10
src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

@ -37,6 +37,14 @@ @@ -37,6 +37,14 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit-console">
<HintPath>..\..\..\..\Tools\NUnit\nunit-console.exe</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="nunit.core">
<HintPath>..\..\..\..\Tools\NUnit\nunit.core.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework">
@ -47,7 +55,9 @@ @@ -47,7 +55,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="NamespaceFilterTests.cs" />
<Compile Include="TestableConditionTests.cs" />
<Compile Include="Utils\MockTestCase.cs" />
<Compile Include="Utils\MockTestTreeView.cs" />
<Compile Include="Utils\MockMember.cs" />
<Compile Include="Utils\MockClass.cs" />

23
src/AddIns/Misc/UnitTesting/Test/Utils/MockTestCase.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using NUnit.Core;
namespace UnitTesting.Tests.Utils
{
public class MockTestCase : TestCase
{
public MockTestCase(string name) : base(null, name)
{
}
public override void Run(TestCaseResult result)
{
}
}
}

10
src/AddIns/Misc/UnitTesting/Test/Utils/MockTestTreeView.cs

@ -17,6 +17,7 @@ namespace UnitTesting.Tests @@ -17,6 +17,7 @@ namespace UnitTesting.Tests
IMember selectedMethod;
IClass selectedClass;
IProject selectedProject;
string selectedNamespace;
public MockTestTreeView()
{
@ -48,5 +49,14 @@ namespace UnitTesting.Tests @@ -48,5 +49,14 @@ namespace UnitTesting.Tests
selectedProject = value;
}
}
public string SelectedNamespace {
get {
return selectedNamespace;
}
set {
selectedNamespace = value;
}
}
}
}

Loading…
Cancel
Save