当前位置:网站首页>gotests自动生成测试用例
gotests自动生成测试用例
2022-08-03 05:26:00 【IT界的测试混子】
发现一个自动生成测试用例的工具gotests。
gotests
https://github.com/cweill/gotests
下载
go get -u github.com/cweill/gotests/...
举个栗子:
add.go
package main
func Add(a int, b int) int {
return a + b
}
同目录下执行
gotests -all -w ./add.go
同目录自动生成 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
}{
// TODO: Add test cases.
}
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)
}
})
}
}
填充用例数据:
package main
import "testing"
func TestAdd(t *testing.T) {
type args struct {
a int
b int
}
tests := []struct {
name string
args args
want int
}{
// TODO: Add test cases.
{
"a=3,b=1",
args{
3, 1},
4,
},
{
"a=3,b=-1",
args{
3, -1},
4,
},
}
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 .就可以跑用例啦
其他参数说明:
$ gotests [options] PATH …
-all generate tests for all functions and methods-excl regexp. generate tests for functions and methods that don’t match. Takes precedence over -only, -exported, and -all
-exported generate tests for exported functions and methods. Takes precedence over -only and -all
-i print test inputs in error messages
-only regexp. generate tests for functions and methods that match only.Takes precedence over -all
-nosubtests disable subtest generation when >= Go 1.7
-parallel enable parallel subtest generation when >= Go 1.7.
-w write output to (test) files instead of stdout
-template_dir Path to a directory containing custom test
code templates. Takes precedence over -template. This can also be set via environment variable GOTESTS_TEMPLATE_DIR
-template Specify custom test code templates, e.g. testify. This can also be set via environment variable GOTESTS_TEMPLATE
-template_params_file read external parameters to template by json
with file
-template_params read external parameters to template by json
with stdin
边栏推荐
- MCU接收串口字符型数据转换成数据型数据
- 电容器和电池有什么不同?
- 数组与字符串15-最大连续1的个数
- PCB设计经验之模拟电路和数字电路区别为何那么大
- 6. What is the difference between Vector, ArrayList and LinkedList?(design, performance, safety)
- ucosII OSMemCreate()函数的解析
- What is parametric design, let's understand it through practical operation?| SOLIDWORKS How-To Videos
- 002_旭日X3派初探:TogetherROS安装
- 队列方法接收串口的数据
- 电子元器件的分类有哪些?
猜你喜欢
随机推荐
3D建模为什么会变得无处不在
SolidWorks 操作视频 | 隐藏高手必备工具Defeature,让设计隐藏更彻底
Automatic ticket issuance based on direct reduction of China Southern Airlines app
各种cms getshell技巧
2021-04-30
ZEMAX | 在OpticStudio中建立扩增实境(VR)头戴式显示器
基于南航app直减自动出票
JSP的基本使用
servlet学习(七)ServletContext
MCU接收串口字符型数据转换成数据型数据
What is parametric design, let's understand it through practical operation?| SOLIDWORKS How-To Videos
All-round interpretation of POE switches (middle)
ue4学习日记2(项目迁移,画刷,附材质)
Typora
ucosII OSMemCreate()函数的解析
九、请介绍类加载过程,什么是双亲委派模型?
VS2022 encapsulates static libraries and calls static libraries under window
A.1#【内存管理】——1.1.1 node:struct pglist_data
SSL证书过期后怎么办?
VLAN虚拟局域网技术









