Discover Packages
github.com/smallnest/go_test_workshop
module
Version:
v0.0.0-...-27f12b6
Opens a new window with list of versions in this module.
Published: Aug 14, 2024
License: MIT
Opens a new window with license information.
README
README
¶
go_test_workshop
如何编写健壮的代码?测试或者单元测试是一个非常有效的手段。自1997年JUint的出世引领单元测试以来,单元测试曾经风靡一时。然后在最近的十年,或者说在最近的几年,互联网企业面临巨大的竞争压力,或者说代码规范不收重视的情况下,糙快猛的编程方式也收到吹捧,以至于单元测试没有收到足够的重视,因此留下来很多的技术债务和线上风险,也就是俗称的"雷"。
这个实战课程,全面介绍Go语言的单元测试的知识,通过大量的实战的代码,带你领略go test的便捷和强大,解答你在实际开发中的众多的疑惑,你在以后的Go应用程序的开发中,可以应用本文介绍的知识,把单元测试威力实际发挥出来。
如果你会写func TestXXX(t *testing.T) {
这一行代码,恭喜你,你已经知道了Go的一半的单元测试的知识,你可以重点关注其它的一半的Go单元测试的知识。如果你还未写过Go的单元测试,没关系,本门课程手把手教你怎么轻轻松松编写Go的单元测试。
本课程的代码放在了 Go Test Workshop
s1: go test basic
s2: testing.T
testing.TB interface
testing.T
Fail/FailNow/Failed/Fatal/Fatalf
Log/Logf/Error/Errorf
Skip/SkipNow/Skipf/Skipped
Helper
Parallel
s3: go test command
s4: coverage
go test -coverprofile cover.out ./...
go-cover-treemap -coverprofile cover.out > out.svg
https://github.com/microsoft/vscode-go/issues/816
https://golang.org/doc/go1.10#test
go tool cover -html=cover.out -o cover.html
go tool cover -o cover2.html -html=cover.out; sed -i 's/black/whitesmoke/g' cover2.html; open cover2.html
mac: go tool cover -o cover2.html -html=cover.out; sed -i'.bak' 's/black/whitesmoke/g' cover2.html; rm -fr cover2.html .bak;open cover2.html
s5: tools
assert/require
gocovery: Behavior-driven Development
s6: mock
s7: web case
dao
service
http
s8: benchmark
s9: example
s10: fuzzing test
go install github.com/rakyll/gotest@master
go install github.com/axw/gocov/gocov@latest
go install github.com/matm/gocov-html@latest
go install github.com/nikolaydubina/go-cover-treemap@latest
// https://go-cover-treemap.io/
Expand ▾
Collapse ▴
Directories
¶
s7
Click to show internal directories.
Click to hide internal directories.