Browse Source

Fixed SD2-1213. The Unit Tests tree view now updates correctly when a duplicate test class has its name changed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3690 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
3521331803
  1. 26
      src/AddIns/Misc/UnitTesting/Src/TestProject.cs
  2. 137
      src/AddIns/Misc/UnitTesting/Test/Project/DuplicateClassNameChangedTestFixture.cs
  3. 3
      src/AddIns/Misc/UnitTesting/Test/Project/TestProjectWithOneClassTestFixture.cs
  4. 1
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

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

@ -178,7 +178,12 @@ namespace ICSharpCode.UnitTesting @@ -178,7 +178,12 @@ namespace ICSharpCode.UnitTesting
// Remove missing classes.
foreach (IClass c in removedClasses.GetMissingClasses()) {
TestClasses.Remove(c.DotNetName);
IClass existingClass = GetExistingTestClassInProject(c);
if (existingClass != null) {
UpdateTestClass(existingClass);
} else {
TestClasses.Remove(c.DotNetName);
}
}
}
@ -262,6 +267,23 @@ namespace ICSharpCode.UnitTesting @@ -262,6 +267,23 @@ namespace ICSharpCode.UnitTesting
rootNamespaces.Add(rootNamespace);
}
}
}
}
/// <summary>
/// Gets an existing test class with the same name in the project. This
/// method is used to check that we do not remove a class after an existing duplicate class name
/// is changed.
/// </summary>
IClass GetExistingTestClassInProject(IClass c)
{
foreach (IClass existingClass in projectContent.Classes) {
if (TestClass.IsTestClass(existingClass)) {
if (existingClass.DotNetName == c.DotNetName) {
return existingClass;
}
}
}
return null;
}
}
}

137
src/AddIns/Misc/UnitTesting/Test/Project/DuplicateClassNameChangedTestFixture.cs

@ -0,0 +1,137 @@ @@ -0,0 +1,137 @@
// <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 System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// SD2-1213 - Creating a unit test with the same name as an existing test
///
/// Two files exist in a project each having the same unit test class. In one file the
/// name of the class is changed. This should result in both test classes being displayed in the unit
/// test tree.
/// </summary>
[TestFixture]
public class DuplicateClassNameChangedTestFixture
{
TestProject testProject;
IProject project;
MockProjectContent projectContent;
[SetUp]
public void Init()
{
// Create a project to display.
project = new MockCSharpProject();
project.Name = "TestProject";
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);
nunitFrameworkReferenceItem.Include = "NUnit.Framework";
ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
// Add a test class.
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
c.SetCompoundClass(c);
MockMethod test1Method = new MockMethod("Test1");
test1Method .DeclaringType = c;
test1Method .Attributes.Add(new MockAttribute("Test"));
c.Methods.Add(test1Method);
// Test 2 method is from a duplicate test class.
MockMethod test2Method = new MockMethod("Test2");
test2Method.DeclaringType = c;
test2Method.Attributes.Add(new MockAttribute("Test"));
c.Methods.Add(test2Method);
projectContent.Classes.Add(c);
testProject = new TestProject(project, projectContent);
// Make sure test methods are created, otherwise
// the Test2 method will never be looked at due to lazy evaluation
// of test method.s
int count = testProject.TestClasses[0].TestMethods.Count;
// Change the name of the second test class.
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
oldUnit.Classes.Add(c);
c.Methods.Remove(test2Method); // Remove duplicate test class method.
// Create new compilation unit with inner class that has its method renamed.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newTestClass = new MockClass("RootNamespace.MyNewTestFixture");
newTestClass.ProjectContent = projectContent;
newTestClass.Attributes.Add(new MockAttribute("TestFixture"));
newTestClass.SetCompoundClass(newTestClass);
projectContent.Classes.Add(newTestClass);
newTestClass.Methods.Add(test2Method);
newUnit.Classes.Add(newTestClass);
testProject.UpdateParseInfo(oldUnit, newUnit);
}
[Test]
public void TwoTestClassesFound()
{
Assert.AreEqual(2, testProject.TestClasses.Count);
}
[Test]
public void NewTestClassFound()
{
AssertTestClassFound("RootNamespace.MyNewTestFixture");
}
[Test]
public void OldTestClassFound()
{
AssertTestClassFound("RootNamespace.MyTestFixture");
}
/// <summary>
/// This test ensures that the existing class in the project content is used to update
/// the test methods. So the any methods from the duplicate test class are removed.
/// </summary>
[Test]
public void OldTestClassHasOneMethod()
{
Assert.AreEqual(1, GetTestClass("RootNamespace.MyTestFixture").TestMethods.Count);
}
[Test]
public void OldTestClassHasOneMethodCalledTest1()
{
Assert.AreEqual("Test1", GetTestClass("RootNamespace.MyTestFixture").TestMethods[0].Name);
}
void AssertTestClassFound(string name)
{
TestClass c = GetTestClass(name);
Assert.IsTrue(c != null);
}
TestClass GetTestClass(string name)
{
foreach (TestClass c in testProject.TestClasses) {
if (c.QualifiedName == name) {
return c;
}
}
return null;
}
}
}

3
src/AddIns/Misc/UnitTesting/Test/Project/TestProjectWithOneClassTestFixture.cs

@ -166,6 +166,7 @@ namespace UnitTesting.Tests.Project @@ -166,6 +166,7 @@ namespace UnitTesting.Tests.Project
public void TestClassInNewCompilationUnitOnly()
{
// Create old compilation unit.
projectContent.Classes.Clear();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
// Create new compilation unit with class that
@ -216,6 +217,7 @@ namespace UnitTesting.Tests.Project @@ -216,6 +217,7 @@ namespace UnitTesting.Tests.Project
public void TestClassRemovedInParserInfo()
{
// Create old compilation unit.
projectContent.Classes.Clear();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
MockClass mockClass = (MockClass)testClass.Class;
mockClass.SetCompoundClass(mockClass);
@ -237,6 +239,7 @@ namespace UnitTesting.Tests.Project @@ -237,6 +239,7 @@ namespace UnitTesting.Tests.Project
public void NewCompilationUnitNull()
{
// Create old compilation unit.
projectContent.Classes.Clear();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
MockClass mockClass = (MockClass)testClass.Class;
mockClass.SetCompoundClass(mockClass);

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

@ -62,6 +62,7 @@ @@ -62,6 +62,7 @@
<Compile Include="NUnitConsoleExeSelectedTestFixture.cs" />
<Compile Include="Project\AbstractBaseClassWithTestMethodsTestFixture.cs" />
<Compile Include="Project\BaseTestMethodTestFixture.cs" />
<Compile Include="Project\DuplicateClassNameChangedTestFixture.cs" />
<Compile Include="Project\InnerClassMethodRenamedTestFixture.cs" />
<Compile Include="Project\InnerClassNameChangesTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixture.cs" />

Loading…
Cancel
Save