Go "no test files" / "no tests to run" in CI - Fix Empty Test Runs
Go reports [no test files] for packages it found no _test.go files in, and no tests to run when a -run filter matched nothing. Often harmless, but it can hide a suite that silently stopped being discovered.
What this error means
go test ./... prints ok <pkg> [no test files] for packages you expected to test, or testing: warning: no tests to run with a PASS. The run is green but exercised nothing in those packages.
ok github.com/yourorg/app/handler (cached)
? github.com/yourorg/app/store [no test files]
# or with a -run filter:
testing: warning: no tests to run
PASSCommon causes
Test files not named *_test.go
Go only treats files ending in _test.go as tests. A file named store_tests.go or test_store.go is compiled as normal source and contributes no tests.
Test functions don’t match the convention
Test functions must be func TestXxx(t *testing.T) with an exported name. A lowercase or wrong-signature function is ignored.
A -run pattern matched nothing
A -run regex that does not match any test name yields no tests to run - a typo or an over-narrow filter.
How to fix it
List what go test discovers
Enumerate the test names so you can see which packages actually contribute tests.
go test -list '.*' ./...Fix naming conventions
- Rename test files to end in
_test.go. - Make test functions
func TestXxx(t *testing.T)with a capitalized name afterTest. - Check any
-runregex actually matches your test names.
Fail CI when whole packages have no tests, if intended
If a package must have tests, assert coverage so an empty package is caught rather than passing silently.
go test -cover ./... | tee cover.txt
grep -q 'no test files' cover.txt && echo 'missing tests' && exit 1 || trueHow to prevent it
- Name test files
*_test.goand functionsTestXxx. - Review
-runfilters so they are not over-narrow. - Track coverage so a package silently losing its tests is visible.