One minute
Splitting Integration and Unit Tests on a Go Project
When working in any software project we usually use more than one test type. Usually we have the unit ones that are fast and don’t require any dependency. All dependencies are mocked or changed for ones that don’t go outside of the application, like in memory repository implementations.
But we also want to test the integration of our application with all external dependencies. Is here when we need to spin up some containers to have databases, third party apis… and many other external services.
For sure will have the need to execute one or the others so to do that we can add this line of code as the first one in all the integration tests:
// +build integration
Now if we run the tests with go test ./...
we’ll see that the integration ones are not being executed.
If we want to add these ones we can just execute them doing that:
go test ./... --tags=integration