Our great sponsors
-
The standard Go testing environment is very good, certainly for unit testing. You might want to use some test helper packages to provide some missing features. For instance, table-driven testing where you have a table of test-specific structures providing inputs and expected results which you iterate over, is a good way of organising your tests. One downside is that the test failure will all be reported from the same line and it can be hard to find the failing test. A useful helper to identify the failing test is the ID struct from github.com/nickwells/testhelper.mod/v2/testhelper which if created using the MkID function will show the filename and line of the failing test. This package also offers standardised comparison checks and support for Golden files and lots more.
-
I come from a .NET background and in the .NET environment I used to seed the database with the necessary data on each test and then clean the database at the end of the test using the Respawn library.
-
SonarLint
Clean code begins in your IDE with SonarLint. Up your coding game and discover issues early. SonarLint is a free plugin that helps you find & fix bugs and security issues from the moment you start writing code. Install from your favorite IDE marketplace today.
Related posts
- testhelper v1.16.0 released with a new DiffVals func - like reflect.DeepEqual but with some useful extra features
- Working with JSON in Go: A Comprehensive Guide
- autogold - automatically update your Go tests
- Best practice for separating DB models from API models?
- Convenient slice handling with generics? See Tideland Go Slices