Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

clion generate tests

github-actions[bot] edited this page Sep 22, 2023 · 2 revisions

Generate tests with default configuration

Make sure the UnitTestBot C/C++ client is connected to the server, and try UnitTestBot C/C++ on a simple example project (e.g., c-example) or go ahead and apply the tool to your real-life code.

Build and configure your project

As soon as you perform the initial setup, two messages appear in the notification area (lower right):

  1. "UTBot: Build directory not found! Build directory does not exist on server filesystem." — select Generate build directory.
  1. "UTBot: Project not configured File compile_commands.json is missing in the build directory." — select Generate Missing JSON Files.

You can also configure the project later: in the Status Bar (lower right), select the UTBot widget and choose Configure Project.

Generate tests

With UnitTestBot C/C++ you can generate tests for a project, a folder, a file, a function, or a line; tests with the prompted result, and tests that fail an assertion.

In the CLion Project tool window, select the folder or a file, right-click and choose the required command:

  • UTBot: Generate Tests For Current File (for a selected file only)
  • UTBot: Generate Tests For Folder
  • UTBot: Generate Tests For Project

In the Editor, place the caret at the function body. Right-click, scroll down the menu, select UTBot Generate Tests... and choose the required option:

  • for Current File

You can generate tests for *.c or *.cpp files.

  • for Current Function

Only public functions (declared in a corresponding header file) are considered as test targets.

  • for Current Line

You can generate tests that cover a specific line.

  • that Fail Current Assertion

We do not recommend to include tests that fail an assertion to a common test suite with regular checks as a failure triggers the engine to terminate test execution.

  • with Prompted Result

UnitTestBot C/C++ cannot solve NP-hard problems, so do not use this feature on hash functions. Set up a condition (an equation or inequation) the target output should satisfy: choose a proper operator (in C syntax) and insert a value (constants supported only).

You can also generate tests for code snippet, which is unrelated to a project: open the snippet, go to Navigate > Search Everywhere and enter UTBot: Generate Tests For Code Snippet.

All these commands are available via Search Everywhere: go to Navigate > Search Everywhere and enter UTBot: Generate Tests.

Note: it may take time to analyze a big project — check the progress bar. Once analysis is completed, the tests folder appears in your project folder: test names look like test_%filename%.cpp.

User guide

Supported syntax

Contributor guides

Developer guides

Advanced

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /