Testing Functions in the Main Package
When testing functions defined in the main package, it's essential to include all relevant files in the testing command. In the example provided, the main.go and main_test.go files should both be specified on the command line.
Additionally, ensure that the test function follows the naming convention TestXXX and takes a pointer to testing.T as an argument. Modifying the main_test.go file as follows will resolve the error:
package main import "testing" func TestFoo(t *testing.T) { t.Error(foo()) }
When running the following command:
go test *.go
The tests should pass.
The above is the detailed content of How to Test Functions in the Main Package?. For more information, please follow other related articles on the PHP Chinese website!