GoLand 2019.2 Help

Go tests

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

  1. Open a file for which you want to create a Go test.

    go sample code

  2. In the Project tool window, right-click the project where you want to create your test file.

  3. From the context menu, select New | Go File.

  4. In the dialog that opens, enter the name of your file. The correct syntax for naming test files is <name>_test.

    go test sample

  5. Create your test or press Alt+Insert to open a context menu with a list of available test templates.
    go generate test

    On how to write benchmark tests, refer to the golang benchmark documentation.

    On how to use gocheck, refer to the gocheck documentation.

  6. Press N/A to run the created test and check results in the Run tool window.
    go test result

    While in the Run tool window you can execute different actions such as rerunning icons toolwindows toolWindowRun svg Ctrl+F5 your test session or rerunning Rerun Failed Tests button failed tests.

If you want to run your test with coverage, in the editor, right-click the icons toolwindows toolWindowRun svg icon on the left gutter and select the Run <name> with Coverage option.

go choose coverage

If you want to see the results of other already saved coverages, do the following:

  1. Press Ctrl+Alt+F6

  2. 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:

  1. From the main menu, select Run | Edit Configurations.

  2. Click the icons general add svg icon on the toolbar and select the Go Test configuration type.

  3. 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 -run parameter of go test.
      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.

  1. In the Before Launch section, click the icons general add svg icon.

  2. In the list that opens, specify what you want to run prior launching your test configuration and click OK.

Last modified: 29 October 2019