Skip to content

Example of Test Tables for new blog Article. 🧪

Notifications You must be signed in to change notification settings

solrac97gr/go-test-tables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Example of Test Tables for new blog Article. 🧪

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published