duanlingzei0170 2017-07-27 15:47
浏览 13
已采纳

您如何为连接到授权帐户的库编写测试?

I'm writing a library that utilizes the gmail API. Pretty much every function needs to connect to the gmail API and to work properly at all it needs to authenticate.

For example, this library has the ability to change email labels, so to test it I could make a dummy account, get credentials, and set up "test emails" in an inbox, change their labels, and check to see if they were changed properly, but how would a third party use that gmail account to perform the unit tests? To use it they'd need access to the account, and that would allow them to change email labels (and other things) and invalidate my unit tests.

Another idea I had was to generate a batch of test emails on-the-fly and then when the tests were done, delete all traces of them. That way each third party that runs the tests would just be able to use their own test accounts.

I'm just wondering if there is a more standard way to do this.

  • 写回答

1条回答 默认 最新

  • duanlian1978 2017-07-27 15:52
    关注

    The best practices is to "mock" or fake all the external dependencies. For example, all the calls of the gmail API should be to a faked interface. You only test that the API has been called with the proper arguments... There a lot of librairies to do the mocks....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?