编译运行一个main 包(package),常用的运行方式如下:
go run .
go run hello
go run 后面接路径,该路径(不含子路径)下所有的go源文件都属于main包。
==go run filename1 filename1 ==
go run 后面接go源文件,这些源文件必须要属于main包(package),并且要列出该程序所需的所有的源文件
但是在module-aware模式下,以上方式是不适用的,go run 命令运行在main包所在的目录下
go run . 或者 go run main函数所在的文件名
go 有一个轻量级(lightweight)的单元测试(unit testing)框架,可以很方便的测试相关函数。在使用此测试框架的时候需要注意以下 几点:
S C:\Users\love1\Documents\technology\go\gopathMode\hello\yyzc> go test -v .\greetings_test.go
#command-line-arguments
greetings_test.go:5:8: found packages greet (greetings.go) and greet1 (greetings_test.go) in C:\Users\love1\Documents\technology\go\gopathMode\hello\yyzc
FAIL command-line-arguments [setup failed]
FAIL
func TestXXX (t *testing.T){
}
否则会报如下错误
:\Users\love1\Documents\technology\go\gopathMode\hello\yyzc\greetings_test.go:8:1: wrong signature for TestHello, must be: func TestHello(t *testing.T)
FAIL command-line-arguments [setup failed]
FAIL
PS C:\Users\love1\Documents\technology\go\gopathMode\hello\yyzc>
go test . 执行当前目录下的所有test文件
go test directory 执行yyzc目录下的所有test文件
go test filename 只执行指定的test文件