golang learning for test - WNXu/LeetCode GitHub Wiki

golang project test learning:

  1. 创建golang 项目,项目名称:go-learn;
  2. 打开idea,在go-learn下创建dir say_hello_dir;
  3. cp say_hello_dir;
  4. new file: say_hello.go;
  5. 在say_hello.go中创建方法:

func SayHello() { fmt.Println("hello world") }

  1. cp say_hello_dir; new file say_hello_test.go;
  2. 在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") } }

  1. cp say_hello_dir;
  2. go test -v; 10.查看执行结果;