I recently read into testing and examples as part of testing testing and did not understand what they were intended for. I see the documentation says:
The package also launches and validates the sample code. Examples of functions may include a closing line comment that begins with "Output:" and compares with the standard output of the function when performing tests. (The comparison ignores the starting and ending spaces.)
However, I do not really appreciate the reason why this will exist. When I write my tests, it seems that it should be more than clear how to use the code just by reading unit tests and tests. What additional motivation does the examples section provide? It seems superfluous to me, but I’m sure that the go inventors put it for a good reason, especially because they seem to sympathize with the good programming practice of designing their language. I hope to understand their motivation or how this part of the language can be used positively in the golang project! :)
go testing
Pinocchio
source share