Go has testing toolchain built right into it. For adding normal integration tests, you don't really need any other libraries. You could use Go's TestMain function to do setup and teardown of test suites.
When there’s a TestMain() function in any of your test files, that function is called directly by go test. The function can then perform any necessary setup, run the tests, and then teardown whatever was needed to support the tests.
You could pass flags to preferentially setup and teardown tests. So if you want to test only the database part of your application, and not the message queue part, you could run the command go test --database provided you have an example test file like the following:
var (
database = flag.Bool("database", false, "run database integration tests")
messageQueue = flag.Bool("messageQueue", false, "run message queue integration tests")
)
func TestMain(m *testing.M) {
flag.Parse()
if *database {
setupDatabase()
}
if *messageQueue {
setupMessageQueue()
}
result := m.Run()
if *database {
teardownDatabase()
}
if *messageQueue {
teardownMessageQueue()
}
os.Exit(result)
}
Jennifer Lauwitz
"Go" get it!
Go has testing toolchain built right into it. For adding normal integration tests, you don't really need any other libraries. You could use Go's
TestMainfunction to do setup and teardown of test suites.When there’s a
TestMain()function in any of your test files, that function is called directly bygo test. The function can then perform any necessary setup, run the tests, and then teardown whatever was needed to support the tests.You could pass flags to preferentially setup and teardown tests. So if you want to test only the database part of your application, and not the message queue part, you could run the command
go test --databaseprovided you have an example test file like the following:var ( database = flag.Bool("database", false, "run database integration tests") messageQueue = flag.Bool("messageQueue", false, "run message queue integration tests") ) func TestMain(m *testing.M) { flag.Parse() if *database { setupDatabase() } if *messageQueue { setupMessageQueue() } result := m.Run() if *database { teardownDatabase() } if *messageQueue { teardownMessageQueue() } os.Exit(result) }