Goでテストカバレッジを出す

Goの標準機能で簡単にテストカバレッジを出せる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
[vagrant(%0)@pit(10.0.2.2) gimmick.git]$ go test -cover ./chord/
ok      github.com/masu-mi/gimmick.git/chord    0.003s  coverage: 90.9% of statements
[vagrant(%0)@pit(10.0.2.2) gimmick.git]$ go test -coverprofile=cover.out ./chord/
ok      github.com/masu-mi/gimmick.git/chord    0.006s  coverage: 90.9% of statements
[vagrant(%0)@pit(10.0.2.2) gimmick.git]$ go tool cover -func=cover.out
github.com/masu-mi/gimmick.git/chord/chord.go:79:       locateSuccessor         87.5%
github.com/masu-mi/gimmick.git/chord/chord.go:93:       closestPrecedingNode    85.7%
github.com/masu-mi/gimmick.git/chord/chord.go:117:      Hash                    66.7%
github.com/masu-mi/gimmick.git/chord/chord.go:123:      hash                    0.0%
github.com/masu-mi/gimmick.git/chord/chord.go:128:      NewNode                 100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:139:      createNewRing           100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:143:      joinRing                100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:153:      stabilize               100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:165:      notify                  100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:174:      fixFigures              100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:191:      checkPredecessor        100.0%
github.com/masu-mi/gimmick.git/chord/chord.go:196:      checkSuccessors         0.0%
github.com/masu-mi/gimmick.git/chord/chord.go:200:      fail                    100.0%
total:                                                  (statements)            89.3%

htmlにも吐けるけどなかなか渋い感じになった。

1
2
3
[vagrant(%0)@pit(10.0.2.2) gimmick.git]$ go tool cover -html=cover.out
HTML output written to /tmp/cover454243479/coverage.html
[vagrant(%0)@pit(10.0.2.2) gimmick.git]$ (cd /tmp/cover454243479/; python -m http.server 8080)
comments powered by Disqus