O'Reilly logo

Go in Action by William Kennedy with Brian Ketelsen and Erik St. Martin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Testing and benchmarking

In this chapter

  • Writing unit tests to validate your code
  • Mocking HTTP-based requests and responses using httptest
  • Documenting your packages with example code
  • Examining performance with benchmarks

Testing your code is not something that you should wait to do until after you’re finished developing your program. With Go’s testing framework, unit testing and benchmarking can happen during the development process. Just like the go build command, there’s a go test command to execute explicit test code that you write. All you need to do is follow a few guidelines, and you can integrate tests into your project and continuous integration systems seamlessly.

9.1. Unit testing

A unit test is a function that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required