This is a follow up issue for https://github.com/golang/go/issues/27927#issuecomment-566686467, which discussed having an alternative mechanism to run tests from within TestMain
. The proposal was the following:
func TestMain(m *testing.M) {
setupAll()
code := m.RunEach(func(t *testing.T) {
setup(t)
t.Run()
teardown(t)
})
teardownAll()
os.Exit(code)
}
Basically, testing.M
should provide a way to iterate through the tests and allow code to be executed before and after each.
Originally posted by @mgwidmann in https://github.com/golang/go/issues/27927#issuecomment-566686467
Comment From: gabyhelp
Related Issues and Documentation
- proposal: testing: add support for individual test function execution - expose testing.M.Tests #53701 (closed)
- proposal: testing: per-test setup and teardown support #27927 (closed)
- testing: add M.Cleanup #42161 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: seankhliao
Duplicate of #53701