栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

go test生成html测试报告

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

go test生成html测试报告

最近项目换成了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:MyProjectGoProject> 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-report

Flags:
-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 test

Use “go-test-report [command] --help” for more information about a
command.

遗留问题:生成的测试用例中,第一条用例会多一条TestAdd

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/906534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号