Catch2 テストの作成

Catch2 テストをビルドおよび実行するには、Catch2 ライブラリとヘッダーをインストールするか、Catch2 リポジトリにある単一のインクルードヘッダーファイルを使用します。

コンパイラとビルドシステムが Catch2 のヘッダーファイルを自動的に検出できる場合は、テストを作成する際にインクルードディレクトリを指定する必要はありません。

基本的な Catch2 テストを作成するには:

  1. File 」 > 「New Project 」 > 「Test Project 」の順に移動します。
  2. Catch2 Test Project 」>「Choose 」を選択し、Catch2テスト用の定型コードを含むプロジェクトを作成します。
  3. Project and Test Information 」ダイアログで、プロジェクトとテストの設定を指定します。

    「Catch2 テストプロジェクト」ウィザードの「プロジェクトおよびテスト情報」ダイアログ

    1. Test framework 」で、「Catch2 v3 (shared libraries) 」を選択してCatch2にリンクするか(バージョン3推奨)、または「Catch2 v2 (header only) 」を選択して単一のヘッダーファイルを含めるようにします(バージョン2推奨)。
    2. Test case name で、テストケースファイルの名前を指定します。
    3. Catch2 install directory (optional) 」で、Catch2 ヘッダーファイルが格納されているディレクトリへのパスを入力できます。
    4. Use own main を選択して、独自に定義した main 関数を使用します。
    5. Use Qt libraries を選択して、Qt 機能を使用するようにプロジェクトを設定します。
    6. Build system 」で、プロジェクトのビルドに使用するビルドシステム(CMake、qmake、または Qbs)を選択します。

Qt Creator プロジェクトディレクトリにテストが作成されます。

Catch2 テストの作成に関する詳細については、Catch2 を参照してください。

注: テストのスキャン中 、パーサーは、一般的な Catch2 ヘッダー(catch2.hppcatch_all.hpp 、その他いくつか)のいずれかを直接または間接的にインクルードしているファイルのみを考慮します。現時点でビルドされないファイルは無視されます。

「ハウツー:テスト」、「ビルドシステムの選択」、「テストも参照してください

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.