我正在为遵循 MVP 模式的小型应用程序编写测试。
从技术上讲,我知道我应该在编写代码之前编写测试,但我需要快速智能地敲出一个演示应用程序,所以我现在要回到测试,然后再进行真正的开发。
简而言之,我正在尝试测试演示者,但是由于 Internal.ExpectationException,我什至无法运行空测试。
在意外调用事件分配时引发异常。
这是演示者类,
public LBCPresenter(IView view, IModel model)
{
m_model = model;
m_model.BatteryModifiedEvent += new EventHandler(m_model_BatteryModifiedEvent);
}
模型接口
public interface IModel
{
event EventHandler BatteryModifiedEvent;
}
这是测试课,我看不出我错过了什么,我告诉 NMock 期待这次活动......
[TestFixture]
public class MVP_PresenterTester
{
private Mockery mocks;
private IView _mockView;
private IViewObserver _Presenter;
private IModel _mockModel;
[SetUp]
public void SetUp()
{
mocks = new Mockery();
_mockView = mocks.NewMock<IView>();
_mockModel = mocks.NewMock<IModel>();
_Presenter = new LBCPresenter(_mockView, _mockModel);
}
[Test]
public void TestClosingFormWhenNotDirty()
{
Expect.Once.On(_mockModel).EventAdd("BatteryModifiedEvent", NMock2.Is.Anything);
//makes no difference if following line is commented out or not
//mocks.VerifyAllExpectationsHaveBeenMet();
}
}
每次我运行测试时,我都会得到相同的期望异常。
有任何想法吗?