This guide provides step-by-step instructions for creating, executing, and verifying Code-Based Tests in a C++ project.

1. Preparing the Project

Code-Based Test requires a C++ project that meets the following conditions.

Requirements Description
Project Type C++ project (C projects are not supported)
Supported Toolchains GCC 5.0 or later
Visual Studio 2015 or later
Clang 8.0 or later
Execution Environment Host Environment (Target Environment is not supported)

2. Creating Tests

  1. Create tests using one of the following two methods.
    • With the [Code-Based Test View] active, click [Create Code-Based Test] on the toolbar.
    • With the [Code-Based Test View] active, click [New Test] on the [Dashboard]
  1. When the test creation dialog opens, enter the following information.
    • Target source file: Select the actual C++ source file to be tested.
    • Test file name: Defaults to the selected source file name + _test.cpp
  1. Click [OK] to create the test file. The generated test is automatically added to the [Code-Based Test View].

3. Writing Test Code

  1. Double-click the generated test file to open the [Code-Based Test Editor].
  1. Write test code using macros such as EXPECT_EQ and ASSERT_TRUE to verify that the function behaves as expected.
    • Macro Auto-Completion: Ctrl + Space
    • Saving Code: Ctrl + S
  1. If the TEST macro syntax is incorrect or the file contains GTest macros not supported by CT, an error marker appears in the left column when the file is saved. After checking the error message, correct the invalid syntax and replace unsupported macros with those supported by CT.

4. Executing Tests

  1. Select the test items to run in the [Code-Based Test View].
  1. After test execution, view the logs of the executed test cases in the [Console View]. Test logs are available in the [Console View]. Logs are not displayed if the view is closed.

5. Checking Test Results and Coverage

Check the test results and coverage in the following locations.

  • [Code-Based Test View]: Test structure and pass/fail status
  • [Console View]: Execution logs for each test case
  • [Coverage View]: Coverage information for functions called during test execution

Need more help with this?
Don’t hesitate to contact us here.

Thanks for your feedback.