I've made simple application in go and trying to run tests with GUI tools of GoLand.
In myfile_test.go file near test func I press green button that should start test. But I get error message: "Compilation failed" and message in console:
# command-line-arguments [command-line-arguments.test]
./myfile_test.go:21:11: undefined: MyStruct
./myfile_test.go:22:12: undefined: MyFuncName
./myfile_test.go:33:12: undefined: AnotherStruct
Compilation finished with exit code 2
Other variants (Run test with Coverage/CPU Profile) don't work either. GoLand 2020.1 EAP. The same problem occurred in older versions of GoLand.
But test from console starts normally:
go test -v
=== RUN TestMyStruct_MyMethod
--- PASS: TestMyStruct_MyMethod (0.00s)
PASS
ok _/home/username/projects/my_project_name 0.002s
Is GoLand available via the JetBrains Toolbox as part of the All Products Pack? Yes, it is available both as a standalone IDE and as a part of the All Products Pack.
Open an existing projectIn the Welcome to IntelliJ IDEA dialog, click Open. Alternatively, click File | Open. In the file browser, navigate to a folder with project files and click Open…. Click OK.
At the command line in the greetings directory, run the go test command to execute the test. The go test command executes test functions (whose names begin with Test ) in test files (whose names end with _test.go). You can add the -v flag to get verbose output that lists all of the tests and their results.
The answer from @porfirion worked for me.
Basically, you need to tick "Enable Go Modules integration" in GoLand under "Preferences" -> "Go" -> "Go Modules"
Goland will then reindex your project and this can take a long time if you have a large project with many modules. Mine took 30 mins. You can check the reindexing progress status at the bottom of the IDE.
The test run will work after the reindexing.
I solved the problem with initializing new go module and enabling Go Modules Integration:
1) Run in Terminal go mod init my_module_name
2) Click "File -> Settings" or press Ctrl+Alt+S
3) Check "Enable Go Modules Integration" and Apply button
Now all test functionality in GoLand works well (including tests with coverage, etc.)
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