味見日報 - Gauge

Posted on 2021/01/28(Thu) 22:05 in technical

味見日報 - Gauge

Gauge

ATDD tool

install

Ubuntu 20.04 LTS

$ sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net --recv-keys 023EDB0B
$ echo deb https://dl.bintray.com/gauge/gauge-deb stable main | sudo tee -a /etc/apt/sources.list.d/gauge.list
$ sudo apt-get update && sudo apt-get install gauge
$ gauge --version
Gauge version: 1.1.7
Commit Hash: 5d86b72

Plugins
-------
No plugins found
Plugins can be installed with `gauge install {plugin-name}`

Quick start

$ mkdir ajimi-guage
$ cd ajimi-guage
$ gauge init python
Initializing template from https://github.com/getgauge/template-python/releases/latest/download/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' version 0.3.14
$ tree
.
├── env
│   └── default
│       ├── default.properties
│       └── python.properties
├── manifest.json
├── requirements.txt
├── specs
│   └── example.spec
└── step_impl
    ├── __init__.py
    └── step_impl.py

4 directories, 7 files

pythonの場合は requirements.txt を入れる。

$ python -m venv ~/.venvs/ajimi-guage
$ source ~/.venvs/ajimi-guage/bin/activate
$ pip install -r requirements.txt
$ gauge run specs
Python: 3.8.5
# Specification Heading
  ## Vowel counts in single word         ✔ ✔
  ## Vowel counts in multiple word       ✔ ✔

Successfully generated html-report to => /home/yuki/dev/ajimi-gauge/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: 39ms

デフォルトだとレポートHTMLファイルが reports ディレクトリに出力される。

step_impl

とりあえずコマンドランナーとか入れとく。

$ pip install invoke

step_impl/invoke.py

from getgauge.python import step, before_scenario, Messages
import invoke

@step("ping to below table: <dest_table>")
def ping(dest_table):
    for dest in dest_table.get_column_values_with_name("dest"):
        result = invoke.run(f"ping -c1 {dest}", hide=True, warn=True)
        assert result.ok

@step(["ping to <dest>", "<dest> にping"])
def ping(dest):
    result = invoke.run(f"ping -c1 {dest}", hide=True, warn=True)
    assert result.ok, str(result)

specs/ping.spec

# Ping example spec

試しにさっき書いたpingを呼ぶ

## Ping successful

step_implでlistにするとaliasになるので、同じ処理コードを呼ぶのに英語表現と日本語表現を混ぜられる。

* ping to "8.8.8.8"
* "8.8.4.4" ping
* "1.1.1.1" ping

## Ping successful by table parameters

* ping to below table:
     | Name   | dest    |
     | ------ | ------- |
     | sv_01  | 8.8.8.8 |
     | sv_02  | 8.8.4.4 |
     | sv_03  | 1.1.1.1 |

## Ping successful by dynamic parameters

     | Name   | dest    |
     | ------ | ------- |
     | sv_01  | 8.8.8.8 |
     | sv_02  | 8.8.4.4 |
     | sv_03  | 1.1.1.1 |

* ping to <dest>

実行。

$ gauge run specs/ping.spec 
Python: 3.8.5
# Ping example spec
  ## Ping successful     ✔ ✔ ✔
  ## Ping successful by table parameters         ✔

   |Name |dest   |
   |-----|-------|
   |sv_01|8.8.8.8|
  ## Ping successful by dynamic parameters       ✔

   |Name |dest   |
   |-----|-------|
   |sv_02|8.8.4.4|
  ## Ping successful by dynamic parameters       ✔

   |Name |dest   |
   |-----|-------|
   |sv_03|1.1.1.1|
  ## Ping successful by dynamic parameters       ✔

Successfully generated html-report to => /home/yuki/dev/ajimi-gauge/reports/html-report/index.html

Specifications: 1 executed      1 passed        0 failed        0 skipped
Scenarios:      3 executed      3 passed        0 failed        0 skipped

Total time taken: 704ms

レポートファイルはこんな感じ

report