How do you unit test a mail sending function

后端 未结 6 2108
礼貌的吻别
礼貌的吻别 2021-01-31 17:41

I have a function which creates a report and sends it to a user. What I\'ve done is create a mock for the email function, and verify if the \'send\' function of the email class

6条回答
  •  执笔经年
    2021-01-31 18:28

    In the past I have sent real e-mails but I used the decorator pattern on the default EMailGateway implementation.

    So I had an EMailGatewayRedirect that would change the recipient to my own address and, in my case, added a line to the top stating that the e-mail is a test and what the original recipient address was.

    Since I use a DI container I simply instantiated the redirection gateway as my IEMailGateway implementation in my integration tests. In this way a real e-mail was sent.

提交回复
热议问题