func check(a, b int) bool {
	return false
}
用 goland 给上面这个函数生成的测试方法
func Test_check(t *testing.T) {
	type args struct {
		a int
		b int
	}
	tests := []struct {
		name string
		args args
		want bool
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := check(tt.args.a, tt.args.b); got != tt.want {
				t.Errorf("check() = %v, want %v", got, tt.want)
			}
		})
	}
}
默认生成的规则是把函数所有的参数放到一个 args 结构体里面。自己不太喜欢这种风格。
我希望是下面这种风格。
func Test_check(t *testing.T) {
	tests := []struct {
		name string
		a    int
		b    int
		want bool
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := check(tt.a, ttb); got != tt.want {
				t.Errorf("check() = %v, want %v", got, tt.want)
			}
		})
	}
}
请教一下 goland 是否可以改成默认用我这种风格。
顺便再请教一个问题:
|      1xhd2015      2024-04-09 13:55:35 +08:00 via iPhone 这个应该是一个叫做 gotests 的工具生成的,你可以手动运行命令行。参考 https://github.com/cweill/gotests |