tests/

directory
v0.0.0-...-86d22a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2017 License: Apache-2.0

README

Testing

Testing is built right into the go tools and the standard library. Testing needs to be a vital part of the development process because it can save you a tremendous amount of time throughout the life cycle of the project. Benchmarking is also a very powerful tool tied to the testing functionality. Aspect of your code can be setup to be benchmarked for performance reviews. Profiling provides a view of the interations between functions and which functions are most heavlily used.

Notes

  • The Go toolset has support for testing and benchmarking.
  • The tools are very flexible and give you many options.
  • Write tests in tandem with development.
  • Example code serve as both a test and documentation.
  • Benchmark throughout the dev, qa and release cycles.
  • If performance problems are observed, profile your code to see what functions to focus on.
  • The tools can interfere with each other. For example, precise memory profiling skews CPU profiles, goroutine blocking profiling affects scheduler trace, etc. Rerun tests for each needed profiling mode.

http://golang.org/pkg/testing/
http://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go
http://saml.rilspace.org/profiling-and-creating-call-graphs-for-go-programs-with-go-tool-pprof
http://golang.org/pkg/net/http/pprof/
https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs
https://github.com/dvyukov/go-fuzz
https://talks.golang.org/2015/dynamic-tools.slide#1
https://vimeo.com/141698770
Structuring Tests in Go - Ben Johnson
Advanced Testing Concepts for Go 1.7 - Marcel van Lohuizen
Parallelize your table-driven tests - rakyll
Advanced Testing with Go - Video - Mitchell Hashimoto
Advanced Testing with Go - Deck - Mitchell Hashimoto
The tragedy of 100% code coverage - Daniel Lebrero's

Code Review

Basic Unit Test (Go Playground)
Table Unit Test (Go Playground)
Mocking Web Server Response (Go Playground)
Testing Internal Endpoints (Go Playground)
Example Test (Go Playground)
Sub Tests (Go Playground)

Look at the profiling topic to learn more about using test to profile code.

Coverage

Making sure your tests cover as much of your code as possible is critical. Go's testing tool allows you to create a profile for the code that is executed during all the tests and see a visual of what is and is not covered.

go test -coverprofile cover.out
go tool cover -html=cover.out

figure1


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
Sample program that implements a simple web service.
Sample program that implements a simple web service.
handlers
Package handlers provides the endpoints for the web service.
Package handlers provides the endpoints for the web service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL