https://github.com/solrac97gr/go-test-tables
Example of Test Tables for new blog Article. 🧪
https://github.com/solrac97gr/go-test-tables
go golang testing tests
Last synced: 12 months ago
JSON representation
Example of Test Tables for new blog Article. 🧪
- Host: GitHub
- URL: https://github.com/solrac97gr/go-test-tables
- Owner: solrac97gr
- Created: 2023-05-05T13:35:39.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-13T03:27:41.000Z (about 3 years ago)
- Last Synced: 2025-03-05T13:14:32.460Z (over 1 year ago)
- Topics: go, golang, testing, tests
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to work with Test Tables and Mocks in Go
For this example we will use 2 external packages:
-gomock
-testify/assert
## Mocks
For the mocks I use gomock. It is a mock framework for Go. It integrates well with Go's built-in testing package, but can be used in other contexts too.
You can see in the file generate-mocks.sh how to generate the mocks.
## Test Tables
For the test tables I use a `map[string]struct{}` with the key being the name of the test and the value being a `struct{}`.
Inside of the struct we add all the external information we will need like parameters.
We also add there 2 functions:
- testSetup: This function will be called before the test is run. It will setup the behavior of the mocks and the test data.
- assertSetup: This function will be called before the test is run. It will setup the mocks and the test data.