Summary
In this chapter, we explored the fundamentals of testing in Go, going through how the built-in testing framework provides everything needed to ensure your API works as expected. We covered the three main ways of testing your application, with unit tests for localized and isolated code testing, integration tests for verifying the correct interaction between components, and E2E tests for validating complete workflows from a user’s perspective as a black box.
We also explored testing patterns such as table-driven tests and mocking. We explored libraries for helping in the testing process, such as testify for assertions, gomock for mocking, and testcontainers for integration testing. We also explored applying all these concepts in our API project, adding all kinds of tests, from unit to E2E tests.
Testing is essential when developing an API to prevent your users from experiencing problems when using your API. Still, there is another tool that complements testing...