# CTest

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/ja-jp/help/clion/llms.txt).

[CTest(英語)](https://cmake.org/cmake/help/latest/manual/ctest.1.html) は、CMake の一部として配布されているテスト自動化ツールです。

> **Note:**
> CTest の最小サポートバージョンは 3.15 です。
>
>
>
> CLion uses the  `ctest`  executable located in the same folder as the toolchain's  `cmake`  executable. 任意の  `ctest`  実行可能ファイルの選択はサポートされていません。

## CTest の実行 / デバッグ構成

When you open a project that uses CTest, CLion detects the tests and automatically creates a run/debug configuration for them. この構成は   すべてのテスト   と呼ばれ、   CTest アプリケーション   テンプレートに基づいています。

`実行構成の編集`  ダイアログで、自動的に作成された構成を編集し、同じタイプの構成をさらに追加できます。

![CTests 用に自動的に作成された構成](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_alltests_config.png)

Procedure: CTest 構成を作成する

1. In the main menu, go to  `実行 | 実行構成の編集​` , click ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg) and select   CTest アプリケーション   from the list of templates:

![CTest アプリケーション構成の追加](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_addconfig.png)

2. 構成名を入力し、設定を指定します。

* 実行するテストリスト フィールドで、含めるテストを選択します。 利用可能なテストのリスト 内でスマート検索を使用すると、ナビゲーションが簡単になります。 ![CTest アプリケーションで利用可能なテストのリスト](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_config_testlist.png) CLion は、使用している `ctest` のバージョンが 3.15 未満の場合、またはプロジェクトでテストが検出されなかった場合に通知します。 ![テスト検出が失敗する警告](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_nodetect_warning.png) この場合、 `設定 | ビルド、実行、デプロイ | ツールチェーン` の CMake のバージョンを確認し、 `CMakeLists.txt` ファイルで CTest テストが有効になっていることを確認してください。 > **Note:** > [正規表現を使用した CTest オプション(英語)](https://cmake.org/cmake/help/v3.7/manual/ctest.1.html#options)を使用してテストのリストをフィルタリングするには、 CTest 引数 フィールドを使用します。

* CTest 引数 フィールドでは、追加のフラグを指定できます。 例: テストでサポートされている場合は、 `--parallel` を指定してテストを並行して実行します。

Other fields of the configuration settings are described on the [reference page](ctest-application.html).

Procedure: CTest テストを起動する

テストを実行またはデバッグするには、次のいずれかのオプションを使用します。

* スイッチャーで構成を選択し、ツールバーアイコンのいずれかをクリックするか、対応するショートカットを使用します。

![構成スイッチャーとツールバー](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_configswitcher.png)

* `CMakeLists.txt`  ファイルを開き、目的のテストに対応する  `add_test`  コマンドを見つけます。 その横にある左側のガターアイコンをクリックして、オプションのリストから選択します。

![テスト用のガターメニュー](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_gutter.png)

ガターアイコンを使用してテストを実行すると、CLion は [一時的な](run-debug-configuration.html) CTest アプリケーション構成を作成しますが、構成のリストではグレー表示されます。 保存するには、  `実行構成の編集`  ダイアログで選択し、 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.save.svg) を押します:

![一時的な構成の保存](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_savetempconfig.png)

Procedure: CTest テストのデバッグ

* If you start a debug session for a CTest test, CLion will run the test itself under debug instead of launching the  `ctest`  child process.

マルチテスト構成の場合、リストから単一のテストを選択するように求められます。

![デバッグ用のテストのリスト](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_debug_testlist.png)

Procedure: 動的解析

* テストに動的分析ツールを使用して、実行時の問題を排除できます。 CLion integrates with [Valgrind Memcheck](memory-profiling-with-valgrind.html), [Google Sanitizers](google-sanitizers.html), [CPU Profiler](cpu-profiler.html), and [Code Coverage](code-coverage-clion.html), providing them with visualized output and handy features to help you work with the results. 詳細については、対応する記事を参照してください。

![テスト用のガターメニューでのプロファイリング](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_gutter_profile.png)

> **Note:**
> デバッグの場合とは異なり、動的分析は  `ctest`  での実行に適用されます。

Procedure: 結果を調べる

* テストを実行すると、CLion は組み込みの [テストランナーウィンドウ](viewing-and-exploring-test-results.html)に結果とプロセスを表示します。 このウィンドウには以下が含まれます。

* これまでに実行されたテストの割合を示す 進捗バー

* 実行中のすべてのテストのステータスと期間を含む ツリービュー

* コンソール output ストリーム

* 失敗した ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.runConfigurations.testState.red2.svg) テストを再実行する、 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.export.svg) をエクスポートする、 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.vcs.history.svg) で自動的に保存された以前の結果を開く、特定のテストを簡単に見つけるために ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.objectBrowser.sorted.svg) のアルファベット順に並べ替える、または ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.runConfigurations.sortbyDuration.svg) の期間で並べ替えて、どのテストが他のテストよりも長く実行されたかを理解するオプションを備えた ツールバー

* テストが宣言されている `CMakeLists.txt` ファイルに移動する ソースに移動 などのアクションを含むコンテキストメニュー。

![テストランナーウィンドウ](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_testrunner.png)

Procedure: テストをスキップする

* 特定の場合、CTest はテストの失敗を無視できます。 これを構成するには、 [SKIP_RETURN_CODE(英語)](https://cmake.org/cmake/help/latest/prop_test/SKIP_RETURN_CODE.html#prop_test:SKIP_RETURN_CODE) または [SKIP_REGULAR_EXPRESSION(英語)](https://cmake.org/cmake/help/latest/prop_test/SKIP_REGULAR_EXPRESSION.html) プロパティを設定します。 CLion will detect these properties and mark the tests as  Skipped  in the output tree:

![テストをスキップする](https://resources.jetbrains.com/help/img/idea/2026.3/cl_ctest_skip.png)

## See also

### オンラインドキュメント

[単体テストのチュートリアル](unit-testing-tutorial.html) [クイック CMake チュートリアル](quick-cmake-tutorial.html)

### プロシージャ

[Run/Debug/Terminate Tests](performing-tests.html) [Explore Test Results](viewing-and-exploring-test-results.html)

### リファレンス

[CTest Application configuration](ctest-application.html)

