golang learning for test - WNXu/LeetCode GitHub Wiki
golang project test learning:
- 创建golang 项目,项目名称:go-learn;
- 打开idea,在go-learn下创建dir say_hello_dir;
- cp say_hello_dir;
- new file: say_hello.go;
- 在say_hello.go中创建方法:
func SayHello() { fmt.Println("hello world") }
- cp say_hello_dir; new file say_hello_test.go;
- 在say_hello_test.go中创建方法:
package say_hello_dir
import ( "testing" )
func TestSayHello(t *testing.T) { res := SayHello("xiao ming", "xiao xue") if res { t.Logf("res:%+v", res) } else { t.Errorf("err : %+v", "test err") } }
- cp say_hello_dir;
- go test -v; 10.查看执行结果;