This content originally appeared on DEV Community and was authored by Daniil Maslov
To understand -race
flag better, we can refer to the Go documentation:
Data races are among the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write.
It is easy to use via the command line interface. So, how to use -race
flag in GoLand with tests? Is it possible to use -race
always in tests? Here you go.
Add -race
flag to a specific test
- Navigate to a test file, click on the gutter icon near the test name and select Modify Run Configuration.
- Add
-race
entry to the Go tool arguments field. - Save changes and run the configuration again.
Add -race
flag to all tests
- Navigate to Help | Find Action in the main menu (Shift+Shift by shortcuts) and type Edit Configurations, press Enter.
- Select the Edit configuration templates option, find Go Test.
- Add
-race
entry to the Go tool arguments field. Pay attention that changing a template does not affect the existing configuration and you should add the flag manually to the same field.
Congratulations! ? Now your tests use -race
flag and you can see warnings from the compiler.
This content originally appeared on DEV Community and was authored by Daniil Maslov

Daniil Maslov | Sciencx (2021-06-29T09:14:06+00:00) Run tests with -race flag in GoLand ?. Retrieved from https://www.scien.cx/2021/06/29/run-tests-with-race-flag-in-goland-%f0%9f%8f%8e/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.