cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.95k stars 345 forks source link

Benchmark test should be avoided #93

Open zerjioang opened 5 years ago

zerjioang commented 5 years ago

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

cweill commented 5 years ago

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

zerjioang commented 5 years ago

@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}