geektutu / blog

极客兔兔的博客,Coding Coding 创建有趣的开源项目。
https://geektutu.com
Apache License 2.0
166 stars 21 forks source link

Go Test 单元测试简明教程 | 快速入门 | 极客兔兔 #61

Open geektutu opened 4 years ago

geektutu commented 4 years ago

https://geektutu.com/post/quick-go-test.html

本文介绍了Go语言(golang) 如何写单元测试(unit tests),详细介绍了标准库 testing 的使用。包括子测试(subtests),帮助函数(helpers),setup 和 teardown 机制,网络测试(Network, http) 和基准测试(benchmark)

wilgx0 commented 3 years ago

您的爱,太阳一般温暖,春风一般和煦,清泉一般甘甜。您的爱,比父爱更严峻,比母爱更细腻,比友爱更纯洁。您的爱,天下最伟大,最高洁。

karezachen commented 3 years ago

写得太好啦!学习了。谢谢博主

dgqypl commented 2 years ago

文中的例子有一处错误:当t.Helper()下一行接t.Run(c.Name, func(t *testing.T) {...的时候,当test case出错时,控制台输出并不会定位到出错的test case那一行代码

cyniczhi commented 2 years ago

网站挂了,求修复

FoBoHuang commented 2 years ago

@dgqypl 文中的例子有一处错误:当t.Helper()下一行接t.Run(c.Name, func(t *testing.T) {...的时候,当test case出错时,控制台输出并不会定位到出错的test case那一行代码

我也遇到了这个问题

wesley2005 commented 2 years ago

@dgqypl 文中的例子有一处错误:当t.Helper()下一行接t.Run(c.Name, func(t *testing.T) {...的时候,当test case出错时,控制台输出并不会定位到出错的test case那一行代码

在"func(t *testing.T) {"后第一行,加t.Helper()即可。