go testing

来源:互联网 发布:mac光盘怎么弹出 编辑:程序博客网 时间:2024/04/30 11:14

官方文档 点击打开链接


demo 如下:


add.go

package simplemathfunc Add(a int, b int) int  {   return a + b}

add_test.go

package simplemathimport "testing"/**在任意目录下运行单元测试如下go test simplemath */func TestAdd1(t *testing.T) {   r := Add(1, 2)   if r != 3 {      t.Errorf("Add(1, 2) failed . Got %的, expect 3. ", r)   }}

运行:

go test simplemath

输出:

ok      simplemath      0.005s


代码见 https://github.com/robertzhai/go/tree/master/go_programming_study/src/simplemath

0 0
原创粉丝点击