Browse Source

Fixed SD2-1359. Incorrect test fixture tested if the base class has unit test methods when running an individual test from the Unit Test tree.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2580 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
82c8dd1a3f
  1. 46
      src/AddIns/Misc/UnitTesting/Src/BaseTestMethod.cs
  2. 3
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  3. 4
      src/AddIns/Misc/UnitTesting/Src/UnitTestCommands.cs
  4. 91
      src/AddIns/Misc/UnitTesting/Test/Project/BaseTestMethodTestFixture.cs
  5. 16
      src/AddIns/Misc/UnitTesting/Test/Project/TestMethodsInBaseClassTestFixture.cs
  6. 1
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  7. 15
      src/AddIns/Misc/UnitTesting/Test/Utils/MockMethod.cs
  8. 1
      src/AddIns/Misc/UnitTesting/UnitTesting.csproj

46
src/AddIns/Misc/UnitTesting/Src/BaseTestMethod.cs

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// <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;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Represents a test method that exists in a base class.
/// </summary>
/// <remarks>
/// In order to have the Unit Test tree run the correct
/// test when we have a class that has a base class with
/// test methods is to return the derived class from the
/// DeclaringType's property. Otherwise the base class
/// method is tested and the derived class is not used.
/// </remarks>
public class BaseTestMethod : DefaultMethod
{
IMethod method;
/// <summary>
/// Creates a new instance of the BaseTestMethod.
/// </summary>
/// <param name="derivedClass">The derived class and not
/// the class where the method is actually defined.</param>
/// <param name="method">The base class's test method.</param>
public BaseTestMethod(IClass derivedClass, IMethod method)
: base(method.Name, method.ReturnType, method.Modifiers, method.Region, method.BodyRegion, derivedClass)
{
this.method = method;
}
/// <summary>
/// Gets the actual method used to create this object.
/// </summary>
public IMethod Method {
get { return method; }
}
}
}

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

@ -328,7 +328,8 @@ namespace ICSharpCode.UnitTesting @@ -328,7 +328,8 @@ namespace ICSharpCode.UnitTesting
if (c.BaseClass != null) {
foreach (IMethod method in c.BaseClass.Methods) {
if (TestMethod.IsTestMethod(method)) {
TestMethod testMethod = new TestMethod(c.BaseClass.Name, method);
BaseTestMethod baseTestMethod = new BaseTestMethod(c, method);
TestMethod testMethod = new TestMethod(c.BaseClass.Name, baseTestMethod);
if (!testMethods.Contains(testMethod.Name)) {
testMethods.Add(testMethod);
}

4
src/AddIns/Misc/UnitTesting/Src/UnitTestCommands.cs

@ -45,6 +45,10 @@ namespace ICSharpCode.UnitTesting @@ -45,6 +45,10 @@ namespace ICSharpCode.UnitTesting
IMember member = treeView.SelectedMethod;
IClass c = treeView.SelectedClass;
if (member != null) {
BaseTestMethod baseTestMethod = member as BaseTestMethod;
if (baseTestMethod != null) {
member = baseTestMethod.Method;
}
GotoMember(member);
} else if (c != null) {
GotoClass(c);

91
src/AddIns/Misc/UnitTesting/Test/Project/BaseTestMethodTestFixture.cs

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
// <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
{
/// <summary>
/// Tests that the BaseTestMethod populates the various
/// properties of the DefaultMethod class in its constructor.
/// </summary>
[TestFixture]
public class BaseTestMethodTestFixture
{
MockClass mockClass;
MockMethod mockMethod;
BaseTestMethod baseTestMethod;
DomRegion mockMethodRegion;
DomRegion mockMethodBodyRegion;
DefaultReturnType returnType;
[TestFixtureSetUp]
public void SetUpFixture()
{
mockClass = new MockClass("Tests.MyTestFixture");
mockMethod = new MockMethod("MyMethod");
mockMethodRegion = new DomRegion(0, 0, 0, 10);
mockMethod.Region = mockMethodRegion;
mockMethodBodyRegion = new DomRegion(1, 0, 2, 5);
mockMethod.BodyRegion = mockMethodBodyRegion;
mockMethod.Modifiers = ModifierEnum.Public;
MockClass returnTypeClass = new MockClass("Tests.ReturnType");
returnType = new DefaultReturnType(returnTypeClass);
mockMethod.ReturnType = returnType;
baseTestMethod = new BaseTestMethod(mockClass, mockMethod);
}
[Test]
public void MethodName()
{
Assert.AreEqual("MyMethod", baseTestMethod.Name);
}
[Test]
public void DeclaringType()
{
Assert.AreEqual(mockClass, baseTestMethod.DeclaringType);
}
[Test]
public void ActualMethod()
{
Assert.AreEqual(mockMethod, baseTestMethod.Method);
}
[Test]
public void MethodRegion()
{
Assert.AreEqual(mockMethodRegion, baseTestMethod.Region);
}
[Test]
public void MethodBodyRegion()
{
Assert.AreEqual(mockMethodBodyRegion, baseTestMethod.BodyRegion);
}
[Test]
public void Modifiers()
{
Assert.AreEqual(ModifierEnum.Public, baseTestMethod.Modifiers);
}
[Test]
public void ReturnType()
{
Assert.IsTrue(Object.ReferenceEquals(returnType, baseTestMethod.ReturnType));
}
}
}

16
src/AddIns/Misc/UnitTesting/Test/Project/TestMethodsInBaseClassTestFixture.cs

@ -38,6 +38,7 @@ namespace UnitTesting.Tests.Project @@ -38,6 +38,7 @@ namespace UnitTesting.Tests.Project
public class TestMethodsInBaseClassTestFixture
{
TestClass testClass;
MockClass c;
[SetUp]
public void SetUp()
@ -55,7 +56,7 @@ namespace UnitTesting.Tests.Project @@ -55,7 +56,7 @@ namespace UnitTesting.Tests.Project
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
MockClass c = new MockClass("RootNamespace.MyTestFixture");
c = new MockClass("RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
MockMethod method = new MockMethod("DerivedMethod");
@ -89,6 +90,19 @@ namespace UnitTesting.Tests.Project @@ -89,6 +90,19 @@ namespace UnitTesting.Tests.Project
Assert.IsTrue(testClass.TestMethods.Contains("TestFixtureBase.BaseMethod"));
}
/// <summary>
/// The TestMethod.Method property should return an IMethod
/// that returns the derived class from the DeclaringType property
/// and not the base class. This ensures that the correct
/// test is run when selected in the unit test tree.
/// </summary>
[Test]
public void BaseMethodDeclaringTypeIsDerivedClass()
{
TestMethod method = testClass.TestMethods["TestFixtureBase.BaseMethod"];
Assert.AreEqual(c, method.Method.DeclaringType);
}
[Test]
public void UpdateTestResultUsingPrefixBaseClassName()
{

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

@ -60,6 +60,7 @@ @@ -60,6 +60,7 @@
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="NamespaceFilterTests.cs" />
<Compile Include="Project\BaseTestMethodTestFixture.cs" />
<Compile Include="TestableConditionTests.cs" />
<Compile Include="Tree\MultipleTestProjectsTestFixture.cs" />
<Compile Include="Tree\TreeNodeContextMenuTestFixture.cs" />

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

@ -14,10 +14,13 @@ namespace UnitTesting.Tests.Utils @@ -14,10 +14,13 @@ namespace UnitTesting.Tests.Utils
public class MockMethod : IMethod
{
IClass declaringType;
ModifierEnum modifiers;
DomRegion region = DomRegion.Empty;
DomRegion bodyRegion = DomRegion.Empty;
IList<IAttribute> attributes = new List<IAttribute>();
string name = String.Empty;
IList<IParameter> parameters = new List<IParameter>();
IReturnType returnType;
public MockMethod() : this(String.Empty)
{
@ -42,7 +45,10 @@ namespace UnitTesting.Tests.Utils @@ -42,7 +45,10 @@ namespace UnitTesting.Tests.Utils
public DomRegion BodyRegion {
get {
throw new NotImplementedException();
return bodyRegion;
}
set {
bodyRegion = value;
}
}
@ -96,10 +102,10 @@ namespace UnitTesting.Tests.Utils @@ -96,10 +102,10 @@ namespace UnitTesting.Tests.Utils
public IReturnType ReturnType {
get {
return null;
return returnType;
}
set {
throw new NotImplementedException();
returnType = value;
}
}
@ -114,9 +120,10 @@ namespace UnitTesting.Tests.Utils @@ -114,9 +120,10 @@ namespace UnitTesting.Tests.Utils
public ModifierEnum Modifiers {
get {
return ModifierEnum.None;
return modifiers;
}
set {
modifiers = value;
}
}

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

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="Src\AllTestsTreeNode.cs" />
<Compile Include="Src\BaseTestMethod.cs" />
<Compile Include="Src\UnitTestCommands.cs" />
<Compile Include="Src\TestableCondition.cs" />
<Compile Include="Src\RunningTestsCondition.cs" />

Loading…
Cancel
Save