Testing
Testing is one of the fundamental aspects of software development. You can decide to write tests before the code (test-driven development, or TDD) or after the code, but you have to write tests of your code to ensure your project remains maintainable as it grows. The Go team knows that. That is why the Go language incorporates a testing tool into the Go distribution.
Go comes with everything you need to write tests for your code, but it doesn’t stop there. There are also a lot of other testing tools and libraries provided by the ecosystem, such as testify for assertions, gomock for mocking, and testcontainers-go for integration testing.
In this chapter, we will cover how you test your Go API using the three main types of testing, and we will learn about the following:
- How to test your API
- Using unit testing and mocks
- Creating integration testing using testcontainers
- End-to-end (E2E) testing of our API using an HTTP client
- Incorporating...