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 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错