Home >Backend Development >Golang >Why Does 'go test' Show 'no tests to run' Even With a Test Function?
Why "no tests to run" Despite Having a Test Function
Go testing requires a specific naming convention for test functions. The function name must begin with an uppercase letter "T" and follow the format TestXxx(t *testing.T).
In the provided code snippet, the test function is named testNormalizePhoneNum, which violates this convention. The testing tool ignores this function, resulting in the "no tests to run" message.
Solution:
To fix this issue, rename the test function to TestNormalizePhoneNum with an uppercase "T":
package main import ( "testing" ) func TestNormalizePhoneNum(t *testing.T) { // ... }
Alternative Solution:
Alternatively, you can force the testing tool to run the function by using the -run flag:
go test -run=testNormalizePhoneNum
However, this approach is not recommended as it bypasses the standard naming convention.
The above is the detailed content of Why Does 'go test' Show 'no tests to run' Even With a Test Function?. For more information, please follow other related articles on the PHP Chinese website!