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

我最近在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项目中以积极的方式使用这部分语言!

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1 Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...