GUIアプリケーションにおいてユーザーインターフェースのテストは重要です。今回はUnityとUbuntuのインストーラーのUIテスト自動化のために開発された、
Autopilotとは
冒頭でも述べたとおりUIのテストは重要なのですが、
しかしこれでは作業コストがかかりすぎてしまいますし、
そこで開発されたのがAutopilotです。AutopilotはPythonで書かれた、
また、
Autopilotを使うと、 それではまずAutopilotをインストールしましょう。Autopilotの動作にはUbuntu 12. 最後のunity-autopilotパッケージは、 同じテストを複数のテストパターン 実際にいくつかのテストを試してみましょう。UIテスト時は、 ゲストセッションに移行したらrunコマンドに実行したテストIDを指定します。端末を開いて次のコマンドを実行してください。 これは、 キーボードやマウスの操作をエミュレートできるため、 ちなみにunityテストスイートのすべてのテストを実行する場合は、 今度は実際にテストを作ってみましょう。Pythonの知識さえあれば誰でもかんたんに作成できます。ユニットテストに触れた経験があるなら、 まず、 Autopilotでは、 そこでファイルの構成としてまずテストスイート名のフォルダーを作り、 以下のようなフォルダーとファイルを作成してください。 __ 編集すべきファイルはtest_ たったこれだけで runコマンドで実行すると 一つのテストケースに複数のテストメソッド そんな時に使えるのがsetUp()とtearDown()と呼ばれるテストフィクスチャーです。テストケースのクラスでオーバーライドすることで、 前節の例では実行した端末上でキーボード入力を行っていました。しかし本来は端末上ではなく、 テストを実行してみると、 マウス操作用のクラスも存在します。test_ 新しく追加したテストを実行すると、 keyboard. ここまでの作業では Autopilotでは各GUIツールキットのイントロスペクションを提供することで、 また、 例えば、 新しく追加したテストを実行しましょう。画面上で文字 AutopilotでUIテストを書くための必要最低限の知識を紹介しました。これをもとにそれぞれのアプリケーションごとにテストを書き始めるわけですが、 前者については、 UIテストとしての機能もまだ十分ではありませんが、 まだ機能が複雑でないうちに、インストールとUnityのテスト
$ sudo apt-get install python-autopilot unity-autopilot
$ autopilot list unity
unity.tests.launcher.test_capture.LauncherCaptureTests.test_launcher_capture_while_not_sticky_and_hidden
unity.tests.launcher.test_capture.LauncherCaptureTests.test_launcher_capture_while_sticky_and_hidden_moving_right
unity.tests.launcher.test_capture.LauncherCaptureTests.test_launcher_captures_while_sticky_and_revealed
unity.tests.launcher.test_capture.LauncherCaptureTests.test_launcher_not_capture_while_not_sticky_and_hidden_moving_right
unity.tests.launcher.test_capture.LauncherCaptureTests.test_launcher_not_capture_while_not_sticky_and_revealed
(以下略)
$ autopilot run unity.tests.test_dash.DashKeyNavTests.test_lensbar_enter_activation
.
----------------------------------------------------------------------
Ran 1 test in 7.302s
OK
$ autopilot run unity.tests.test_ibus.IBusTestsAnthy.test_anthy
............
----------------------------------------------------------------------
Ran 12 tests in 86.568s
OK
$ autopilot run unity
もっと簡単なサンプル
$ sudo add-apt-repository ppa:autopilot/ppa
$ sudo apt-get update
$ sudo apt-get upgrade
もしくは
$ sudo apt-get python-autopilot
ひな形を作る
.
└── Recipe
├── __init__.py
└── test_sample.py
# -*- coding: utf-8 -*-
from autopilot.testcase import AutopilotTestCase
class SampleTests(AutopilotTestCase):
def test_keyboard(self):
self.keyboard.type("Hello autopilot")
$ autopilot list Recipe
Loading tests from: /home/shibata/Sample
Recipe.test_sample.SampleTests.test_keyboard
1 total tests.
$ autopilot run Recipe.test_sample.SampleTests.test_keyboard
Loading tests from: /home/shibata/Sample
Tests running...
Hello autopilot
Ran 1 test in 3.200s
OK
setUp()とtearDown()
# -*- coding: utf-8 -*-
from autopilot.testcase import AutopilotTestCase
class SampleTests(AutopilotTestCase):
def setUp(self):
super(SampleTests, self).setUp()
self.app = self.start_app("Text Editor")
def test_keyboard(self):
self.keyboard.type("Hello autopilot")
マウスの操作
def test_mouse(self):
self.keyboard.press_and_release("Super+Ctrl+Up")
self.mouse.move(0, 0)
self.mouse.click(button=1)
$ autopilot run Recipe.test_sample.SampleTests.test_mouse
テスト結果の確認
from autopilot.testcase import AutopilotTestCase
from autopilot.emulators.clipboard import get_clipboard_contents
from autopilot.matchers import Eventually
from testtools.matchers import Equals
(中略)
def test_clipboard(self):
self.keyboard.type("Hello autopilot")
self.keyboard.press_and_release("Ctrl+a")
self.keyboard.press_and_release("Ctrl+c")
self.assertThat(get_clipboard_contents, Eventually(Equals("Hello autopilot")))
$ autopilot run Recipe.test_sample.SampleTests.test_clipboard
Loading tests from: /home/shibata/Sample
Tests running...
Ran 1 test in 5.277s
OK
まとめ