AppCode 2020.2 Help

Google Test support

Google Test and Google Mock are a pair of powerful unit testing tools: the framework is portable, it includes a rich set of fatal and non-fatal assertions, provides instruments for creating fixtures and test groups, gives informative messages, and exports the results in XML. Probably the only drawback is a need to build gtest/gmock in your project in order to use it.

Generate menu for Google Test

Use Generate menu to save time on writing test code: in a file where you have gtest included, press ⌘N to see the list of code generation options.

When called from a fixture, this menu additionally includes SetUp Method and TearDown Method:

generate menu for tests

For fixture tests, code generation converts TEST() macros into the appropriate TEST_F(),TEST_P(), TYPED_TEST(), or TYPED_TEST_P() (see Typed Tests).

Google Test run/debug configuration

Although Google Test provides the main() entry, and you can run tests as regular applications, we recommend using the dedicated Google Test run/debug configuration. It includes test-related settings and let you benefit from the built-in test runner, which is unavailable if you run tests as regular programs.

  1. To create a Google Test configuration, go to Run | Edit Configurations, click icons.general.add.svg and select Google Test from the list of templates.

  2. Specify the test or suite to be included in the configuration, or provide a pattern for filtering test names. Auto-completion is available in the fields to help you quickly fill them up:

    completion in configuration fields

    Set wildcards to specify test patterns, for example:

    pattern for tests

    In other fields of the configuration settings, you can set environment variables and command line options. For example, use Program arguments field to pass the --gtest_repeat flag and run a Google test multiple times:

    flags in program arguments

    The output will look as follows:

    Repeating all tests (iteration 1) ... Repeating all tests (iteration 2) ... Repeating all tests (iteration 3) ...

  3. Save the configuration, and it's ready for Runicons.actions.execute.svg or Debugicons.actions.startDebugger.svg.

Running tests

In AppCode, there are several ways to start a run/debug session for tests, one of which is using special gutter icons. These icons help quickly run or debug a single test or a whole suite/fixture:

gutter icons for tests

Gutter icons also show test results (when already available): success icons.runConfigurations.testState.green2.svg or failure icons.runConfigurations.testState.red2.svg.

When you run a test/suite/fixture using gutter icons, AppCode creates a temporary Google Test configuration, which is greyed out in the configurations list. To save a temporary configuration, select it in the Edit Configurations dialog and press

Last modified: 08 September 2020