cweill / gotests

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

t.Parallel() #107

Closed kaihendry closed 4 years ago

kaihendry commented 5 years ago

Can these tests be generated to be run in parallel?

https://twitter.com/peterbourgon/status/1169414085097607168

cweill commented 5 years ago

@kaihendry If you'd like to add this as a feature, feel free to submit a PR, and I will approve it.

skovtunenko commented 4 years ago

Hello, @zolotov!

With this feature merged into the origin/develop, it would be great to take advantage of it in the IntelliJ IDEA/GoLand IDEs. At least the tc := tc // capture range variable part of the generated code example:

func TestGroupedParallel(t *testing.T) {
    for _, tc := range tests {
        tc := tc // capture range variable
        t.Run(tc.Name, func(t *testing.T) {
            t.Parallel()
            ...
        })
    }
}

Motivation: it's always safer to capture for loop range variables. If someone later on decided to run subtest as Parallel, there would be one less chance to miss the mentioned tc := tc. It looks like this is aligned with Jetbrain's goals to make developer life less error-prone.

zolotov commented 4 years ago

@skovtunenko Hi!

I don't think it relates to gotests project, so could you file a feature request on GoLand tracker instead, please? Also, it would be nice if you provide the code with problem to catch, the current code is fine as tc is not used in any goroutine.