
最近项目换成了go语言。测试用例的也都是go语言写的。想生成个HTML类型的测试报告,找了一圈,终于找到了这个模板。分享给大家。
github地址:
https://github.com/vakenbolt/go-test-report
go get -u github.com/vakenbolt/go-test-report/
下面举个栗子。
add.go
package main
func Add(a int, b int) int {
return a + b
}
add_test.go
package main
import "testing"
func TestAdd(t *testing.T) {
type args struct {
a int
b int
}
tests := []struct {
name string
args args
want int
}{
{
"a=3,b=1",
args{3, 1},
4,
},
{
"a=3,b=-1",
args{3, -1},
4,
},
{
"a=-2,b=-1",
args{-2, -1},
-3,
},
{
"a=-2,b=0",
args{-2, -1},
-3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Add(tt.args.a, tt.args.b); got != tt.want {
t.Errorf("Add() = %v, want %v", got, tt.want)
}
})
}
}
执行
go test -json | go-test-report
D:\MyProject\GoProject> go test -json | go-test-report
[go-test-report] finished in 2.155308s
同目录默认生成test_report.html文件,如下
点击红色的小方块,可以看到详情,如下
其他参数说明:
Usage:
go-test-report [flags]
go-test-report [command]Available Commands: help Help about any command version
Prints the version number of go-test-reportFlags:
-g, --groupSize int the number of tests per test group
indicator (default 20)
-h, --help help for go-test-report
-o, --output string the HTML output file (default “test_report.html”)
-s, --size string the size (in pixels) of the clickable indicator for test result groups (default “24”)
-t, --title string the title text shown in the test report (default “go-test-report”)
-v, --verbose while processing, show the complete output from go testUse “go-test-report [command] --help” for more information about a
command.
遗留问题:生成的测试用例中,第一条用例会多一条TestAdd
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)