【初心者向け】CMakeでGUIテスト: SquishTestScriptモジュールによる実践ガイド


SquishTestScript モジュールは、以下の機能を提供します。

  • テストレポートの生成
  • テスト結果の収集
  • GUI テストスクリプトの起動

SquishTestScript モジュールを使用するには、以下の手順が必要です。

  1. Squish をインストールする
  2. SquishTestScript モジュールを CMake プロジェクトに追加する
  3. テストスクリプトを作成する
  4. CMakeLists.txt ファイルでテストスクリプトをビルドする

SquishTestScript モジュールを使用する例を以下に示します。

cmake_minimum_required(VERSION 3.10)

project(myproject)

find_package(Squish REQUIRED)

squish_add_test(mytest mytest.tst)

add_executable(myproject myproject.cpp)

target_link_libraries(myproject Squish::Test)

この例では、mytest.tst という名前のテストスクリプトが myproject という名前のプロジェクトに追加されます。テストスクリプトは myproject.cpp という名前の実行可能ファイルにリンクされます。

SquishTestScript モジュールに関する詳細については、以下のリソースを参照してください。



例 1: 単純なテストスクリプト

# This script tests the functionality of a button

# Get the button object
button = findObject("Button1")

# Click the button
click(button)

# Verify that the button is clicked
assert("Button1 is clicked", isClicked(button))

このスクリプトは、Button1 という名前のボタンをクリックし、ボタンがクリックされたことを検証します。

例 2: テストデータを使用したテストスクリプト

# This script tests the functionality of a text field using test data

# Define test data
test_data = [
    ["John Doe", "[email protected]"],
    ["Jane Doe", "[email protected]"],
]

# Get the text field object
textField = findObject("TextField1")

# Iterate over test data and enter each value into the text field
for data in test_data:
    name = data[0]
    email = data[1]

    enter(textField, name)
    assert("Name is entered correctly", getText(textField) == name)

    enter(textField, email)
    assert("Email is entered correctly", getText(textField) == email)

このスクリプトは、TextField1 という名前のテキストフィールドにテストデータをを入力し、データが正しく入力されたことを検証します。

cmake_minimum_required(VERSION 3.10)

project(myproject)

find_package(Squish REQUIRED)

squish_add_test(mytest mytest.tst)

add_executable(myproject myproject.cpp)

target_link_libraries(myproject Squish::Test)


以下に、SquishTestScript の代替手段として検討すべきいくつかのオプションを紹介します。

どの代替手段が最適かは、プロジェクトの要件によって異なります。 以下は、各オプションを選択する際に考慮すべきいくつかの要因です。

  • コミュニティとサポート: 一部のツールには、他のツールよりも大きなコミュニティとサポートがあります。これは、問題が発生した場合に役立つ場合があります。
  • プログラミング言語: 一部のツールは特定のプログラミング言語で記述されています。たとえば、Robot Framework は Python で記述されていますが、Selenium は Java、Python、C# などで記述されています。
  • サポートされているテストの種類: すべてのツールがすべての種類のテストをサポートしているわけではありません。たとえば、Robot Framework は GUI テストに適していますが、Selenium は Web アプリケーションのテストに適しています。