testing/

directory
v0.0.0-...-4344c7c Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2016 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

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)

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