Browse Source

Unit tests window no longer displays the base class test method when it is overridden in the derived class.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5366 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
ffb4c4c103
  1. 10
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  2. 84
      src/AddIns/Misc/UnitTesting/Test/Project/OverriddenBaseTestMethodTestFixture.cs
  3. 1
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  4. 16
      src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs

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

@ -329,8 +329,14 @@ namespace ICSharpCode.UnitTesting @@ -329,8 +329,14 @@ namespace ICSharpCode.UnitTesting
if (TestMethod.IsTestMethod(method)) {
BaseTestMethod baseTestMethod = new BaseTestMethod(declaringType, method);
TestMethod testMethod = new TestMethod(c.BaseClass.Name, baseTestMethod);
if (!testMethods.Contains(testMethod.Name)) {
testMethods.Add(testMethod);
if (method.IsVirtual) {
if (!testMethods.Contains(method.Name)) {
testMethods.Add(testMethod);
}
} else {
if (!testMethods.Contains(testMethod.Name)) {
testMethods.Add(testMethod);
}
}
}
}

84
src/AddIns/Misc/UnitTesting/Test/Project/OverriddenBaseTestMethodTestFixture.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// <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 ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class OverriddenBaseTestMethodTestFixture
{
TestClass testClass;
MockClass c;
[SetUp]
public void SetUp()
{
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
// Create the base test class.
MockClass baseClass = new MockClass("ICSharpCode.Tests.BaseClass");
baseClass.ProjectContent = projectContent;
// Add a virtual method to base class.
MockMethod baseMethod = new MockMethod("VirtualTestMethod");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseMethod.DeclaringType = baseClass;
baseMethod.IsVirtual = true;
baseClass.Methods.Add(baseMethod);
// Add a second method that is virtual but will not be overriden.
baseMethod = new MockMethod("VirtualNonOverriddenTestMethod");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseMethod.DeclaringType = baseClass;
baseMethod.IsVirtual = true;
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
c = new MockClass("ICSharpCode.Tests.DerivedClass");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Create a new test method that overrides one of the base class methods.
MockMethod method = new MockMethod("VirtualTestMethod");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = c;
method.IsOverride = true;
c.Methods.Add(method);
// Set derived class's base class.
c.BaseClass = baseClass;
// Create TestClass.
testClass = new TestClass(c);
}
[Test]
public void NonOverriddenVirtualBaseMethodExists()
{
Assert.IsTrue(testClass.TestMethods.Contains("BaseClass.VirtualNonOverriddenTestMethod"));
}
[Test]
public void VirtualBaseMethodDoesNotExistSinceItIsOverriddenInDerivedClass()
{
Assert.IsFalse(testClass.TestMethods.Contains("BaseClass.VirtualTestMethod"));
}
[Test]
public void DerivedClassTestMethodExists()
{
Assert.IsTrue(testClass.TestMethods.Contains("VirtualTestMethod"));
}
}
}

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

@ -68,6 +68,7 @@ @@ -68,6 +68,7 @@
<Compile Include="Project\InnerClassTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixtureAttributeRemovedTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixtureBase.cs" />
<Compile Include="Project\OverriddenBaseTestMethodTestFixture.cs" />
<Compile Include="Project\RemovedClassesTestFixture.cs" />
<Compile Include="Project\TwoBaseClassesWithTestMethodsTestFixture.cs" />
<Compile Include="TestableConditionTests.cs" />

16
src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs

@ -21,6 +21,8 @@ namespace UnitTesting.Tests.Utils @@ -21,6 +21,8 @@ namespace UnitTesting.Tests.Utils
string name = String.Empty;
IList<IParameter> parameters = new List<IParameter>();
IReturnType returnType;
bool isVirtual;
bool isOverride;
public MockMethod() : this(String.Empty)
{
@ -190,10 +192,9 @@ namespace UnitTesting.Tests.Utils @@ -190,10 +192,9 @@ namespace UnitTesting.Tests.Utils
}
}
public bool IsVirtual {
get {
throw new NotImplementedException();
}
public bool IsVirtual {
get { return isVirtual; }
set { isVirtual = value; }
}
public bool IsPublic {
@ -238,10 +239,9 @@ namespace UnitTesting.Tests.Utils @@ -238,10 +239,9 @@ namespace UnitTesting.Tests.Utils
}
}
public bool IsOverride {
get {
throw new NotImplementedException();
}
public bool IsOverride {
get { return isOverride; }
set { isOverride = value; }
}
public bool IsOverridable {

Loading…
Cancel
Save