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 ...

Get Go in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.