Browse Source

Support using fields to define tests in the Unit Tests window.

pull/23/head
Matt Ward 14 years ago
parent
commit
05074fd052
  1. 8
      src/AddIns/Analysis/UnitTesting/Src/TestClass.cs
  2. 12
      src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs
  3. 4
      src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs
  4. 51
      src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs
  5. 1
      src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj

8
src/AddIns/Analysis/UnitTesting/Src/TestClass.cs

@ -274,10 +274,10 @@ namespace ICSharpCode.UnitTesting @@ -274,10 +274,10 @@ namespace ICSharpCode.UnitTesting
TestMethodCollection GetTestMethods(IClass c)
{
TestMethodCollection testMethods = new TestMethodCollection();
foreach (IMethod method in c.Methods) {
if (IsTestMethod(method)) {
if (!testMethods.Contains(method.Name)) {
testMethods.Add(new TestMethod(method));
foreach (IMember member in c.AllMembers) {
if (IsTestMethod(member)) {
if (!testMethods.Contains(member.Name)) {
testMethods.Add(new TestMethod(member));
}
}
}

12
src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs

@ -12,7 +12,7 @@ namespace ICSharpCode.UnitTesting @@ -12,7 +12,7 @@ namespace ICSharpCode.UnitTesting
public class TestMethod
{
string prefix = String.Empty;
IMethod method;
IMember method;
TestResultType testResultType = TestResultType.None;
/// <summary>
@ -20,7 +20,7 @@ namespace ICSharpCode.UnitTesting @@ -20,7 +20,7 @@ namespace ICSharpCode.UnitTesting
/// </summary>
public event EventHandler ResultChanged;
public TestMethod(IMethod method)
public TestMethod(IMember method)
{
this.method = method;
}
@ -41,16 +41,16 @@ namespace ICSharpCode.UnitTesting @@ -41,16 +41,16 @@ namespace ICSharpCode.UnitTesting
///
/// RootNamespace.DerivedClass.BaseClass.BaseClassMethod
/// </param>
public TestMethod(string prefix, IMethod method)
public TestMethod(string prefix, IMember method)
{
this.method = method;
this.prefix = prefix;
}
/// <summary>
/// Gets the underlying IMethod for this TestMethod.
/// Gets the underlying IMember for this TestMethod.
/// </summary>
public IMethod Method {
public IMember Method {
get { return method; }
}
@ -58,7 +58,7 @@ namespace ICSharpCode.UnitTesting @@ -58,7 +58,7 @@ namespace ICSharpCode.UnitTesting
/// Updates the test method based on new information
/// in the specified IMethod.
/// </summary>
public void Update(IMethod method)
public void Update(IMember method)
{
this.method = method;
}

4
src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.UnitTesting @@ -24,9 +24,9 @@ namespace ICSharpCode.UnitTesting
}
/// <summary>
/// Gets the underlying IMethod for this test method.
/// Gets the underlying IMember for this test method.
/// </summary>
public IMethod Method {
public IMember Method {
get {
return testMethod.Method;
}

51
src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests
{
TestClass testClass;
MockClass fakeClass;
MockTestFramework fakeTestFramework;
MockRegisteredTestFrameworks fakeRegisteredTestFrameworks;
void CreateTestClass()
{
fakeClass = MockClass.CreateMockClassWithoutAnyAttributes();
fakeTestFramework = new MockTestFramework();
fakeRegisteredTestFrameworks = new MockRegisteredTestFrameworks();
fakeRegisteredTestFrameworks.AddTestFrameworkForProject(fakeClass.Project, fakeTestFramework);
testClass = new TestClass(fakeClass, fakeRegisteredTestFrameworks);
}
DefaultField AddTestFieldDefinedAsTestMemberToClass(string name)
{
var field = new DefaultField(fakeClass, name);
fakeClass.Fields.Add(field);
fakeRegisteredTestFrameworks.AddTestMethod(field);
return field;
}
[Test]
public void TestMethods_ClassHasOneFieldDefinedAsTestMemberByTestFramework_FirstItemHasSameNameAsField()
{
CreateTestClass();
AddTestFieldDefinedAsTestMemberToClass("MyField");
TestMethod testField = testClass.TestMethods[0];
string testFieldName = testField.Name;
Assert.AreEqual("MyField", testFieldName);
}
}
}

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

@ -90,6 +90,7 @@ @@ -90,6 +90,7 @@
<Compile Include="Project\OverriddenBaseTestMethodTestFixture.cs" />
<Compile Include="Project\RemovedClassesTestFixture.cs" />
<Compile Include="Project\TestClassIsTestMethodUsesTestFrameworksTestFixture.cs" />
<Compile Include="Project\TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs" />
<Compile Include="Project\TestProjectUsesTestFrameworksTestFixture.cs" />
<Compile Include="Project\TwoBaseClassesWithTestMethodsTestFixture.cs" />
<Compile Include="Tree\AddNUnitReferenceToProjectTestFixture.cs" />

Loading…
Cancel
Save