0
我被困在一個單元測試中,測試事件被事件監聽器附加到類並分離。我無法弄清楚如何做到這一點,我已經在很多論壇上看過。 EmailEventListener
將構造函數中的事件附加到fakeClass
,並拆分Detach()
方法。它還包含在事件觸發時調用的方法。我正在使用FakeItEasy創建假類。有什麼想法嗎?謝謝!單元測試事件監聽器正在將事件附加到類中或將其分離
[TestMethod]
public void EmailEventListener_AttachedSubscription_ToClass_Successfully()
{
EmailEventListener<ConcreteClass> realListener = new EmailEventListener<ConcreteClass>(fakeClass, A.Dummy<IEmailSender>());
// Assert that fakeClass has the event
realListener.Detach();
// Assert that fakeClass does not have the event (probably in another test, but just wanted to show it here)
}
不要測試次要的基礎結構事情,測試當涉及到*業務邏輯*時,該類是否暴露了期望的行爲。 – BartoszKP