skip to content
Alvin Lucillo

Test Main

/ 1 min read

💻 Tech

In Go, you can create a func TestMain(m *testing.M) to run some processes like DB preparation before calling m.Run() to call all tests in the same package as the main test. Note that there should only be one main test in one package.

One use case for this is setting up environment variables or testcontainers.