Browse Source

Fixed SD2-1203 - Modifying the namespace for a test class leaves empty namespace nodes in the test tree. The TestNamespaceTreeNode was incorrectly determining when it was is empty when the node was not expanded. Added extra tests to improve the code coverage for the TestTreeView, TestClassesCollection and UnitTestApplicationStartHelper classes. Removed the unused UpdateResult method in TestClass.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2041 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
1ab593a725
  1. 34
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  2. 23
      src/AddIns/Misc/UnitTesting/Src/TestNamespaceTreeNode.cs
  3. 1
      src/AddIns/Misc/UnitTesting/Src/TestTreeView.cs
  4. 18
      src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs
  5. 42
      src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs
  6. 39
      src/AddIns/Misc/UnitTesting/Test/UnitTestCommandLineTests.cs

34
src/AddIns/Misc/UnitTesting/Src/TestClass.cs

@ -355,40 +355,6 @@ namespace ICSharpCode.UnitTesting @@ -355,40 +355,6 @@ namespace ICSharpCode.UnitTesting
}
}
/// <summary>
/// Updates the result of this class based on the results of
/// its methods.
/// </summary>
void UpdateResult()
{
bool failure = false;
bool ignored = false;
bool notRun = false;
foreach (TestMethod method in TestMethods) {
switch (method.Result) {
case TestResultType.None:
notRun = true;
break;
case TestResultType.Failure:
failure = true;
break;
case TestResultType.Ignored:
ignored = true;
break;
}
if (failure) {
break;
}
}
if (failure) {
Result = TestResultType.Failure;
} else if (ignored) {
Result = TestResultType.Ignored;
} else if (!notRun) {
Result = TestResultType.Success;
}
}
/// <summary>
/// First tries the last dotted part of the test result name as the
/// method name. If there is no matching method the preceding dotted

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

@ -96,6 +96,25 @@ namespace ICSharpCode.UnitTesting @@ -96,6 +96,25 @@ namespace ICSharpCode.UnitTesting
}
base.Dispose();
}
/// <summary>
/// Gets whether this namespace node is considered empty. If
/// the node has been expanded then the node is empty if it
/// has no child nodes. If it has not been expanded then there
/// will be a dummy child node or a set of namespace
/// nodes but no test class nodes.
/// </summary>
public bool IsEmpty {
get {
if (isInitialized) {
return Nodes.Count == 0;
} else if (dummyNode != null) {
return testClasses.Count == 0;
} else {
return Nodes.Count == 0 && testClasses.Count == 0;
}
}
}
/// <summary>
/// Adds the test class nodes for this namespace when the
@ -265,7 +284,7 @@ namespace ICSharpCode.UnitTesting @@ -265,7 +284,7 @@ namespace ICSharpCode.UnitTesting
if (e.TestClass.Namespace == fullNamespace) {
// Remove test class from our monitored test classes.
testClasses.Remove(e.TestClass);
// Remove the corresponding tree node.
foreach (ExtTreeNode node in Nodes) {
TestClassTreeNode classNode = node as TestClassTreeNode;
@ -289,7 +308,7 @@ namespace ICSharpCode.UnitTesting @@ -289,7 +308,7 @@ namespace ICSharpCode.UnitTesting
/// </summary>
void RemoveIfEmpty()
{
if (Nodes.Count == 0) {
if (IsEmpty) {
Remove();
Dispose();
TestNamespaceTreeNode parentNode = Parent as TestNamespaceTreeNode;

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

@ -180,7 +180,6 @@ namespace ICSharpCode.UnitTesting @@ -180,7 +180,6 @@ namespace ICSharpCode.UnitTesting
return selectedNode.TestProject;
}
return null;
}
}

18
src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs

@ -165,5 +165,23 @@ namespace UnitTesting.Tests.Project @@ -165,5 +165,23 @@ namespace UnitTesting.Tests.Project
TestMethod method = testProject.TestClasses.GetTestMethod("RootNamespace.Tests.MyTestFixture.TestMethod1");
Assert.AreSame(testMethod1, method);
}
[Test]
public void FindTestMethodFromUnknownTestMethod()
{
Assert.IsNull(testProject.TestClasses.GetTestMethod("RootNamespace.Tests.MyTestFixture.UnknownTestMethod"));
}
[Test]
public void FindTestMethodFromUnknownTestClass()
{
Assert.IsNull(testProject.TestClasses.GetTestMethod("RootNamespace.Tests.UnknownTestFixture.TestMethod1"));
}
[Test]
public void FindTestMethodFromInvalidTestMethodName()
{
Assert.IsNull(testProject.TestClasses.GetTestMethod(String.Empty));
}
}
}

42
src/AddIns/Misc/UnitTesting/Test/Tree/SolutionOpenedTestFixture.cs

@ -157,6 +157,13 @@ namespace UnitTesting.Tests.Tree @@ -157,6 +157,13 @@ namespace UnitTesting.Tests.Tree
Assert.AreSame(expectedTestProject, base.TestTreeView.GetTestProject(project));
}
[Test]
public void GetTestProjectFromUnknownProject()
{
MSBuildProject project = new MSBuildProject();
Assert.IsNull(base.TestTreeView.GetTestProject(project));
}
/// <summary>
/// Tests that an empty project node after being expanded
/// will update itself if a new class is added to the project.
@ -269,6 +276,41 @@ namespace UnitTesting.Tests.Tree @@ -269,6 +276,41 @@ namespace UnitTesting.Tests.Tree
Assert.AreEqual(0, testsNamespaceNode.Nodes.Count);
}
/// <summary>
/// SD2-1203. The namespace tree nodes were not removing
/// themselves when they were empty if they were not expanded
/// first. This test makes sure this problem is fixed.
/// </summary>
[Test]
public void EmptyNamespaceNodesRemovedWhenChildNamespaceNodeNotExpanded()
{
// Expand the project node.
TestProjectTreeNode projectNode = (TestProjectTreeNode)base.TestTreeView.Nodes[0];
projectNode.Expanding();
// Add a new class to a non-empty namespace so it gets
// added to a new namespace node.
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
TestClass testClass = new TestClass(mockClass);
projectNode.TestProject.TestClasses.Add(testClass);
// Get the root namespace node.
TestNamespaceTreeNode rootNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0];
// Check that the rootNamespaceNode does not consider itself
// empty.
Assert.IsFalse(rootNamespaceNode.IsEmpty);
// Expand RootNamespace tree node.
rootNamespaceNode.Expanding();
// Remove the test class from the test project.
projectNode.TestProject.TestClasses.Remove(testClass);
Assert.AreEqual(0, projectNode.Nodes.Count,
"Namespace nodes should have been removed from project node.");
}
/// <summary>
/// Returns a dummy toolstrip so the UnitTestsPad can be
/// tested. If the default method is called the AddInTree

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

@ -10,6 +10,7 @@ using ICSharpCode.Core; @@ -10,6 +10,7 @@ using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests
{
@ -112,6 +113,19 @@ namespace UnitTesting.Tests @@ -112,6 +113,19 @@ namespace UnitTesting.Tests
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
}
[Test]
public void TestMethodSpecifiedInInitialize()
{
MockClass testFixture = new MockClass("TestFixture");
MockMethod testMethod = new MockMethod("Test");
helper.Initialize(project, testFixture, testMethod);
helper.NoLogo = false;
helper.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /fixture=\"TestFixture\" /testMethodName=\"TestFixture.Test\"";
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
}
[Test]
public void FullCommandLine()
{
@ -124,5 +138,30 @@ namespace UnitTesting.Tests @@ -124,5 +138,30 @@ namespace UnitTesting.Tests
string expectedFullCommandLine = "\"C:\\SharpDevelop\\bin\\Tools\\NUnit\\nunit-console.exe\" \"C:\\Projects\\MyTests\\MyTests.dll\" /nologo";
Assert.AreEqual(expectedFullCommandLine, helper.GetCommandLine());
}
/// <summary>
/// Tests that a space is appended between the items added
/// to the UnitTestApplicationStartHelper.Assemblies
/// when the command line is generated.
/// </summary>
[Test]
public void SecondAssemblySpecified()
{
helper.Initialize(project, null, null);
helper.Assemblies.Add("SecondAssembly.dll");
helper.NoLogo = false;
helper.ShadowCopy = true;
helper.Results = @"C:\results.txt";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" \"SecondAssembly.dll\" /results=\"C:\\results.txt\"";
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
}
[Test]
public void GetProject()
{
helper.Initialize(project, null, null);
Assert.AreSame(project, helper.Project);
}
}
}

Loading…
Cancel
Save