GoLand lets you create and run tests using the following Go test frameworks:
gotest – for running standard unit tests
gocheck – for extending your standard test packaging and running more complex tests
gobench – for running performance tests
Creating and running Go tests
Open a file for which you want to create a Go test.
In the Project tool window, right-click the project where you want to create your test file.
From the context menu, select.
In the dialog that opens, enter the name of your file. The correct syntax for naming test files is <name>_test.
- Create your test or press Alt+Insert to open a context menu with a list of available test templates.
On how to write benchmark tests, please refer to the golang benchmark documentation.
On how to use gocheck, please refer to the gocheck documentation.
- Press N/A to run the created test and check results in the Run tool window.
While in the Run tool window you can execute different actions such as rerunning (Ctrl+F5) your test session or rerunning failed tests.
If you want to run your test with coverage, in the editor, right-click the icon on the left gutter and select the Run <name> with Coverage option.
If you want to see the results of other already saved coverages, do the following:
In the dialog that opens, select a coverage you want to display and click Show Selected to see coverage results.
Creating a run/debug configuration for Go tests
If you need to access the Run/Debug Configurations dialog or create a new run configuration, do the following:
On the main menu, select.
Click the icon on the toolbar and select the Go Test configuration type.
- Specify the Go Test configuration settings. They default settings are enough to create an executable run configuration, but if you need, you can specify the following Go-specific options:
Test framework – if you want to create other then plain unit test configuration, select either gocheck or gobench.
Pattern – use this field to filter what tests to run. It sets
If the field is empty then filters are not set and GoLand will run all tests.
Go tool arguments – use this field to specify different go commands.
You can also create a configuration for other tasks or Go commands that would depend on your main configuration.
In the Before Launch section, click the icon.
In the list that opens, specify what you want to run prior launching your test configuration and click OK.