Browse Source

Prevent IronPython unit test framework from showing fields that start with test as unit tests.

pull/23/head
Matt Ward 14 years ago
parent
commit
30fea3c7d0
  1. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs
  2. 39
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestMemberTests.cs

5
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs

@ -12,8 +12,9 @@ namespace ICSharpCode.PythonBinding
{ {
public bool IsTestMember(IMember member) public bool IsTestMember(IMember member)
{ {
if (member != null) { var method = member as IMethod;
return member.Name.StartsWith("test"); if (method != null) {
return method.Name.StartsWith("test");
} }
return false; return false;
} }

39
src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestMemberTests.cs

@ -3,6 +3,7 @@
using System; using System;
using ICSharpCode.PythonBinding; using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop.Dom;
using NUnit.Framework; using NUnit.Framework;
using PythonBinding.Tests.Utils; using PythonBinding.Tests.Utils;
using UnitTesting.Tests.Utils; using UnitTesting.Tests.Utils;
@ -14,32 +15,54 @@ namespace PythonBinding.Tests.Testing
{ {
PythonTestFramework testFramework; PythonTestFramework testFramework;
[SetUp] void CreateTestFramework()
public void Init()
{ {
testFramework = new PythonTestFramework(); testFramework = new PythonTestFramework();
} }
[Test] [Test]
public void IsTestMemberReturnsTrueForMethodThatStartsWithTest() public void IsTestMember_MethodThatStartsWithTest_ReturnsTrue()
{ {
CreateTestFramework();
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
MockMethod method = new MockMethod(c, "testRunThis"); MockMethod method = new MockMethod(c, "testRunThis");
Assert.IsTrue(testFramework.IsTestMember(method));
bool result = testFramework.IsTestMember(method);
Assert.IsTrue(result);
} }
[Test] [Test]
public void IsTestMemberReturnsFalseForNull() public void IsTestMember_NullPassed_ReturnsFalse()
{ {
Assert.IsFalse(testFramework.IsTestMember(null)); CreateTestFramework();
bool result = testFramework.IsTestMember(null);
Assert.IsFalse(result);
} }
[Test] [Test]
public void IsTestMemberReturnsFalseForMethodThatDoesNotStartWithTest() public void IsTestMember_MethodThatDoesNotStartWithTest_ReturnsFalse()
{ {
CreateTestFramework();
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
MockMethod method = new MockMethod(c, "RunThis"); MockMethod method = new MockMethod(c, "RunThis");
Assert.IsFalse(testFramework.IsTestMember(method));
bool result = testFramework.IsTestMember(method);
Assert.IsFalse(result);
}
[Test]
public void IsTestMember_FieldThatStartsWithTest_ReturnsFalse()
{
CreateTestFramework();
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
var field = new DefaultField(c, "testField");
bool result = testFramework.IsTestMember(field);
Assert.IsFalse(result);
} }
} }
} }

Loading…
Cancel
Save