Is there any way for me to easily run a Go test many times, halting the first time it fails? I can of course do something like this:
for i in {1..1000}; do go test ./mypkg && done
but that causes a recompile every time, which is very slow compared to the test
itself. I imagine I could do this with some clever application of the -exec
flag and xargs
, but I am not good at one-liners.
Bonus points for running it many times in parallel with some semblance of sane verbose output if it fails one or two out of a thousand times.
To disable test caching, use any test flag or argument other than the cacheable flags. The idiomatic way to disable test caching explicitly is to use -count=1.
go test : to run all _test.go files in the package. go test -v : will display the result of all test cases with verbose logging. go test -run TestFunctionName/Inputvalue= : to run the test case for specific input. Here I run the `TestSumNumbersInList` for only the 5th index of input.
By default, execution of test code using the testing package will be done sequentially. However, note that it is only the tests within a given package that run sequentially. If tests from multiple packages are specified, the tests will be run in parallel at the package level.
To launch the test under the cursor, invoke the test runner via Ctrl + Shift + F10 on Windows/Linux or ^ + ⇧ + R on macOS.
It is probably new feature - but you can use -count N
to specify how many times to repeat each test. Probably worth mentioning it will run them with a single compilation.
I have to thank Florin Pățan for noticing that in a Github discussion we recently had.
You can pass the -c
flag to go test
which will, per the help:
Compile the test binary to pkg.test but do not run it. (Where pkg is the last element of the package's import path.)
So you can at least avoid recompiling every single time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With