ATDDなTest Framework GaugeをPythonで触ってみる

Markdownでテストスペックの記載可能+テストステップの実装を多くの言語で記載可能とのことで巷で話題のTest Framework GaugeをPythonで試してみたいと思います。

環境

インストール

macOSの場合はgaugeをhomebrewからinstall するだけです。

$ brew install gauge
$ gauge --version
Gauge version: 1.0.3

最新の1.0.3がインストールされました。

Gaugeプロジェクトの初期化

テストを書き始める前に、Gaugeプロジェクトが必要になります。

プロジェクトの初期化を行うには gauge init <lang name> を実施する必要があります。これにより、テストを記載する際に必要なライブラリがインストールされるようです。

今回はタイトルの通り、Pythonで初期化を行いました。

$ mkdir gaugetest; cd gaugetest
$ gauge init python
Downloading python.zip
.
Copying Gauge template python to current directory ...
Successfully initialized the project. Run specifications with "gauge run specs/".
Compatible language plugin python is not installed. Installing plugin...
.
Successfully installed plugin 'python'.

Telemetry
---------

This installation of Gauge collects usage data in order to help us improve your experience.
The data is anonymous and doesn't include command-line arguments.
To turn this message off opt in or out by running 'gauge telemetry on' or 'gauge telemetry off'.

Read more about Gauge telemetry at https://gauge.org/telemetry

テストの実行

上記したプロジェクトの初期化を行うと、必要なライブラリ他、サンプルのSpecとPython実装のStepsも一緒にダウンロードされるため、テストを書かずともテストの実行が可能です。

テストの実行は gauge run <path/to/spec> で行います。

$ gauge run specs
Compatible version of plugin html-report not found. Installing plugin html-report...
.......................
Successfully installed plugin 'html-report'.
Installing required plugins.
.....................
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# Specification Heading
  ## Vowel counts in single word     ✔ ✔
  ## Vowel counts in multiple word   ✔ ✔

Successfully generated html-report to => /Users/ihysk/workspace/gaugetest/reports/html-report/index.html
Specifications: 1 executed  1 passed    0 failed    0 skipped
Scenarios:  2 executed  2 passed    0 failed    0 skipped

Total time taken: 197ms

Telemetry
---------

This installation of Gauge collects usage data in order to help us improve your experience.
The data is anonymous and doesn't include command-line arguments.
To turn this message off opt in or out by running 'gauge telemetry on' or 'gauge telemetry off'.

Read more about Gauge telemetry at https://gauge.org/telemetry

テストの実施とともに必要なPluginもインストールされるようです。

テスト結果

テスト結果はコンソール出力上でも確認できますが、今回のサンプルでは以下のような形のhtml 形式のレポートも自動生成されます。

f:id:siro_uma:20190114224040p:plain:w600

まとめ

Gauge + Pythonを試してみました。とりあえずサンプルのテストを実行するだけなら、何もプログラミングせずに実行可能でした。

次回は自分でStepやSpecを記載してみて、その利便性を確かめたいと思います。