goでライブラリのテストを試す
” testing”パッケージがある
これを使用してテストすることができるみたい
テスト対象
$ tree $GOPATH/src/github.com/mshige1979/ $GOPATH/src/github.com/mshige1979/ ├── compute │ └── add.go └── hello └── hello.go 2 directories, 2 files $
※computeとかいうサンプルライブラリ
テストコード
add_test.go
package compute import ( "testing" ) func TestAdd(t *testing.T){ const in1 = 10 const in2 = 20 const out = 30 x := Add(in1, in2) if x != out { t.Error("Add(%d, %d) = %d\n Error!!!", in1, in2, x) } }
※ファイル名に"_test"を付与するらしい
テスト
$ go test PASS ok github.com/mshige1979/compute 0.009s $
テストちょっと詳しく
$ go test -v === RUN TestAdd --- PASS: TestAdd (0.00s) PASS ok github.com/mshige1979/compute 0.008s $
こんな感じらしい