Browse Source

The unit tests window was not colouring the tree nodes when running a test when a test fixture had a base class with test methods but no TestFixture attribute (e.g. CecilLayerTests class).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3032 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
1b1e268cac
  1. 2
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  2. 115
      src/AddIns/Misc/UnitTesting/Test/Project/AbstractBaseClassWithTestMethodsTestFixture.cs
  3. 1
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

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

@ -383,7 +383,7 @@ namespace ICSharpCode.UnitTesting @@ -383,7 +383,7 @@ namespace ICSharpCode.UnitTesting
TestMethod GetPrefixedTestMethod(string testResultName)
{
IClass baseClass = c.BaseClass;
if (baseClass != null && TestClass.IsTestClass(baseClass)) {
if (baseClass != null) {
string methodName = TestMethod.GetMethodName(testResultName);
string actualMethodName = String.Concat(baseClass.Name, ".", methodName);
return GetTestMethod(actualMethodName);

115
src/AddIns/Misc/UnitTesting/Test/Project/AbstractBaseClassWithTestMethodsTestFixture.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
// <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 ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using System;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// The Unit Tests window was not updating the tree when a test was run if the test
/// was in an abstract base class that did not use the [TestFixture] attribute.
///
/// This is the case with the CecilLayerTests class:
///
/// [TestFixture]
/// public class CecilLayerTests : ReflectionOrCecilLayerTests
/// { ... }
///
/// public abstract class ReflectionOrCecilLayerTests
/// {
///
/// [Test]
/// public void InheritanceTest()
/// { ... }
/// }
///
/// Note that the test result for the test method is written to the file with the name
/// Namespace.CecilLayerTests.InheritanceTests but the unit tests window displays it with the
/// base class name prefixed to it to be consistent with NUnit GUI.
/// </summary>
[TestFixture]
public class AbstractBaseClassWithTestMethodsTestFixture
{
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.SharpDevelop.Tests.ReflectionOrCecilLayerTests");
baseClass.ProjectContent = projectContent;
MockMethod baseMethod = new MockMethod("InheritanceTests");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseMethod.DeclaringType = baseClass;
baseClass.Methods.Add(baseMethod);
// Add a second method that does not have a Test attribute.
baseMethod = new MockMethod("NonTestMethod");
baseMethod.DeclaringType = baseClass;
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
c = new MockClass("ICSharpCode.SharpDevelop.Tests.CecilLayerTests");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Set derived class's base class.
c.BaseClass = baseClass;
// Create TestClass.
testClass = new TestClass(c);
}
[Test]
public void BaseMethodExists()
{
Assert.IsTrue(testClass.TestMethods.Contains("ReflectionOrCecilLayerTests.InheritanceTests"));
}
[Test]
public void NonTestBaseMethodDoesNotExist()
{
Assert.IsFalse(testClass.TestMethods.Contains("ReflectionOrCecilLayerTests.NonTestMethod"));
}
/// <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["ReflectionOrCecilLayerTests.InheritanceTests"];
Assert.AreEqual(c, method.Method.DeclaringType);
}
[Test]
public void UpdateTestResult()
{
TestClassCollection testClasses = new TestClassCollection();
testClasses.Add(testClass);
TestResult testResult = new TestResult("ICSharpCode.SharpDevelop.Tests.CecilLayerTests.InheritanceTests");
testResult.IsFailure = true;
testClasses.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);
}
}
}

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

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

Loading…
Cancel
Save