gotests icon indicating copy to clipboard operation
gotests copied to clipboard

Benchmark test should be avoided

Open zerjioang opened this issue 6 years ago • 2 comments

When selecting -all in gotests, Benchmark functions should be avoided for test generation purposes.

zerjioang avatar Apr 04 '19 15:04 zerjioang

@zerjioang: This does sound like a bug. Can you please provide an example code file where this happens?

cweill avatar Apr 07 '19 17:04 cweill

@cweill, when I execute the gotests with -all flag, the functions with following header definition:

func BenchmarkGetState(b *testing.B){}

are also treated as test candidate generating following code snippet:

func TestBenchmarkGetState(t *testing.T) {
	type args struct {
		b *testing.B
	}
	tests := []struct {
		name string
		args args
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			BenchmarkGetState(tt.args.b)
		})
	}
}

I wont consider this as a bug, but could be a great improvement for those project that have Test functions and Benchmarks.

The way I found to fix this is using the regular expression option an running it via:

${GOPATH}/bin/gotests -excl Benchmark.* -w ${file}

zerjioang avatar Apr 09 '19 19:04 zerjioang