Go testify Suite Tests Not Running - Missing the suite Entry Point
A testify/suite test runs only if a normal func TestXxx(t *testing.T) calls suite.Run(t, new(MySuite)). Without that entry point - or with mis-named methods - go test finds no tests and the suite silently does nothing.
What this error means
go test reports "ok" with "no tests to run" (or 0 assertions) even though the suite file has many Test... methods. The methods are defined on the suite struct but never execute because nothing bootstraps them.
--- ok example/users 0.002s [no tests to run]
// users_test.go defines (s *UserSuite) TestCreate(), TestDelete()
// but there is no func TestUserSuite(t *testing.T) { suite.Run(...) }Common causes
No top-level Test function calls suite.Run
go test only invokes functions matching func TestXxx(t *testing.T). Suite methods are not discovered directly - a single TestXxx must call suite.Run(t, new(Suite)) to drive them.
Method names not prefixed with Test
testify runs only suite methods whose names start with Test. A method named CreateUser (no Test prefix) is treated as a helper and never run.
How to fix it
Add the suite entry point
Provide one TestXxx that runs the suite; name test methods with a Test prefix.
func TestUserSuite(t *testing.T) {
suite.Run(t, new(UserSuite))
}
func (s *UserSuite) TestCreate() { /* ... */ }
func (s *UserSuite) TestDelete() { /* ... */ }Check receivers and naming
- Ensure the suite embeds
suite.Suiteand methods use a pointer receiver. - Prefix every runnable method with
Test. - Run
go test -vto confirm each suite method now appears in the output.
How to prevent it
- Always pair a suite with a
TestXxxthat callssuite.Run. - Name suite test methods with the
Testprefix. - Use
go test -vto verify suite methods are discovered.