Go (Golang) Test Coverage Tutorial

Описание к видео Go (Golang) Test Coverage Tutorial

Test Coverage is a metric used to measure the amount of code that has been covered by unit test within a test suite or a project.
The Go (Golang) Toolchain provides all the tools necessary to measure and improve test coverage within your project and test suite. By using the Go test command and the Go tool Cover command you can generate and inspect test coverage for your Go tests.

Show test coverage
$ go test -cover

Save Cover profile
$ go test -coverprofile=cover.txt

Analyse Cover profile
$ go tool cover -html=cover.txt
$ go tool cover -func=cover.txt

The way (mode) Go test cover analyses and count test coverage can be tweaked such that we get visibility on how often certain branches of code are tested in respect to others. The Go test command accepts a flag -mode which can be set to one of the following options

- set: did each statement run?
- count: how many times did each statement run?
- atomic: like count, but counts precisely in parallel programs

By default it is set to "set". You can specify as follows
$ go test -coverprofile=cover.txt -mode=count


Source Code - https://play.golang.org/p/cRme03gkQSd

Official Blog Post on Go (Golang) Test Coverage tooling - https://blog.golang.org/cover

Go Basic Testing Tutorial -    • Go (Golang) Testing Tutorial  

💼 Golang Cafe - https://golang.cafe
📬 Golang Cafe Jobs Newsletter - https://golang.cafe/newsletter
🐦 Golang Cafe Twitter -   / golangcafe  
📣 Telegram Channel - https://t.me/golangcafe
🙏 Found this video useful? Help me make more by donating $5.00 - https://golang.cafe/5USD

Комментарии

Информация по комментариям в разработке