我最近围绕只有setter的属性创建了一个测试,今天我修改了属性以包含接口中的getter,然后测试用例失败。单元测试仅通过setter属性传递,仅通过将属性添加到属性来失败
我已经创建了一个下面的工作和失败的例子。 我不确定它是否显示我的无知,或者是Rhino.Mocks或NUnit中出现这种行为的错误。
我会appreaciate任何输入。
我在Windows 7 64位上使用Visual Studio 2010。 我使用Rhino.Mocks 3.6(2.6尝试建立21以及用于相同的结果) 我使用NUnit,2.5.10.11092
using NUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
namespace PropertyTestFailure
{
public interface ITest
{
int SetOnlyProperty { set; }
int SetGetProperty { get; set; }
}
/// <summary>
/// The property with getter fails.
/// It appears purely adding the getter that breaks things.
/// </summary>
[TestFixture]
public class TestCase
{
[Test]
public void SetOnlyPropertyWorks()
{
var mockTest = MockRepository.GenerateStub<ITest>();
mockTest.SetOnlyProperty = 23;
mockTest.AssertWasCalled(x => x.SetOnlyProperty
= Arg<int>.Matches(new PredicateConstraint<int>(y => y == 23)));
}
[Test]
public void SetGetPropertyFails()
{
var mockTest = MockRepository.GenerateStub<ITest>();
mockTest.SetGetProperty = 24;
mockTest.AssertWasCalled(x => x.SetGetProperty
= Arg<int>.Matches(new PredicateConstraint<int>(y => y == 24)));
}
}
}
故障报告消息。
SetGetPropertyFails : FailedRhino.Mocks.Exceptions.ExpectationViolationException : ITest.set_SetGetProperty(Predicate (TestCase.<SetGetPropertyFails>b__5(obj);)); Expected #1, Actual #0.
at Rhino.Mocks.RhinoMocksExtensions.AssertWasCalled(T mock, Action`1 action, Action`1 setupConstraints)
at PropertyTestFailure.TestCase.SetGetPropertyFails() in TestCase.cs: line 40
什么是失败的消息? –
好吧,这很快,我已经完全忘记了模拟诗的存根行为。有点困惑,它现在与模拟工作,只有一个二传手。谢谢。 –
这些不是你真正的考验吗?你不需要测试那些简单的setter/getters工作。 – tvanfosson