加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

go(golang)测试框架中的“示例”有什么意义?

发布时间:2020-12-16 19:26:49 所属栏目:大数据 来源:网络整理
导读:我最近在go测试框架中阅读了 testing and examples,并没有真正理解它们的用途.我看到文档说: The package also runs and verifies example code. Example functions may include a concluding line comment that begins with “Output:” and is compared w
我最近在go测试框架中阅读了 testing and examples,并没有真正理解它们的用途.我看到文档说:

The package also runs and verifies example code. Example functions may include a concluding line comment that begins with “Output:” and is compared with the standard output of the function when the tests are run. (The comparison ignores leading and trailing space.)

但是,我真的不明白这会存在的原因.在我编写测试时,似乎只是通过阅读单元测试和基准测试来了解如何使用代码.示例部分提供了哪些额外的动机?对我来说这似乎是多余的,但是,我确信go的发明者有充分的理由,特别是因为他们似乎通过设计他们的语言来理解良好的编程实践.我希望能够理解他们的动机或者如何在golang项目中以积极的方式使用这部分语言!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读