How do you unit test a mail sending function

后端 未结 6 2110
礼貌的吻别
礼貌的吻别 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:35

    There is a very simple way to test the email contents in approvaltests (www.approvaltests.com)or nuget)

    The code is simply:

     EmailApprovals.Verify(mail);
    

    This will create the .eml file, and allow you to view the result in outlook. Future .more, once you approve the result (rename the file to .approved) the test will pass without opening Outlook.

    I have created and uploaded a short video on the process to YouTube.

提交回复
热议问题