私は、私のgo langテストのブランチカバレッジを得る方法があることを示唆する人もいます。golangテストのブランチカバレッジを取得する
package main
import (
"fmt"
)
func HelloWorld(name string, printv int) string {
if name == "tuk" || printv == 1 {
fmt.Println("Hello tuk")
return "Hello tuk"
} else {
fmt.Println("Who are you?")
return "Who are you?"
}
}
対応するテストファイルは以下のようになります - - :のは、私は以下のように見える、外出先コードを持っているとしましょう
package main
import "testing"
func TestHelloWorld(t *testing.T) {
r := HelloWorld("tuk", 0)
if r != "Hello tuk" {
t.Error("Test Failed")
}
}
私は以下のテストコマンドを実行すると、それはちょうど私の文を与えていますカバレッジ: -
go test -coverprofile=cover.out .
ok test 0.007s coverage: 60.0% of statements
ブランチカバレッジを取得する方法はありますか?
私は、-htmlレポートがブランチカバレッジを見つける良い方法だと思います。 – jsxqf