Qt テストの作成

Qt CreatorQt Testフレームワークを統合します。

注意: Qt テストの実行と結果の表示は、Qt 5 以降でサポートされています。

Qt テストを作成するには、以下の手順に従います:

  1. File >New Project >Test Project に移動します。
  2. を選択します。 Qt Test Project>Choose を選択します。
  3. Project and Test Information ダイアログで、プロジェクトとテストの設定を指定します。

    Qt Test Project ウィザードの Project and Test Information ダイアログ

  4. Test case name に、テスト・ケースの名前を入力します。
  5. Requires QApplication を選択して、QApplication の include 文をプロジェクトのmain.cpp ファイルに追加します。
  6. Qt アプリケーションを作成するには、GUI Application を選択します。
  7. Generate initialization and cleanup code を選択して、テストの初期化とクリーンアップのためにテスト フレームワークが実行する関数をテストに追加します。
  8. Build system で、プロジェクトのビルドに使用するビルドシステムを選択します:CMake、qmake、または Qbs です。Qt 5 または Qt 6.4 以前で開発する場合に CMake を使用してビルドするには、CMake for Qt 5 and Qt 6 を選択します。

Qt Creator を選択すると、指定したプロジェクトディレクトリにテストが作成されます。.cpp ファイルを編集して、テスト内の各テスト関数にプライベートスロットを追加します。

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

注意: テストをスキャンしている間、パーサーはQTest またはQtTest またはそれと同等のQtTest/qtest.h を直接的または間接的に含み、プロジェクトのビルド時にQTestLib に対してリンクされるファイルのみを考慮します。現在ビルドされないファイルは無視されます。

注意: General >Process arguments を有効にすると、テストを実行し、1 つ以上のログファイルを並行して書き込むことができます。そのためには出力形式オプション-o filename,format を使用します。Qt Creator がこの出力チャンネルを使用しているため、filename に標準出力を使用することはできない。

How To: Test」、「Select the build system」、「Testing」、「Test Results」、「Logging Options」も参照してください

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.