Go Test

gaojie @Joy :/media/gaojie/Linux/Go/workspace/test/src$ tree
.
├── main.go
└── main_test.go


0 directories, 2 files



gaojie@Joy$ cat main.go
package main


func Add(i int, j int) int{
	return i+j
}
 gaojie@Joy$ cat main_test.go    
package main

import "testing"
//要测试方法前增加"Test"开头
func TestAdd(t *testing.T){
	if (Add(2, 4) == 6){
		t.Log("ok pass")
	}else{
		t.Error("error")
	}
}


你可能感兴趣的:(test,Go)