37
1 Python Developers Camp 2008 冬 in 冬冬

Python Autotest pdc2008w

Embed Size (px)

DESCRIPTION

Python auto test with buildbot. (Python 自動テスト)

Citation preview

Page 1: Python Autotest pdc2008w

1

Python Developers Camp2008 冬 in 松本

Page 2: Python Autotest pdc2008w

2

テスト自動化

Buildbot & Selenium

http:// 清水川 .jp/

Page 3: Python Autotest pdc2008w

3

アジェンダ•Buildbot

–実行の流れ–デモ–しくみ

•Selenium

Page 4: Python Autotest pdc2008w

4

Buildbot

Page 5: Python Autotest pdc2008w

5

UnitTest を書くclass TestCricket(unittest.TestCase): def test_throw(self): cricket = Cricket() cricket.throw(18,1) self.assertEqual( cricket.score(18),1)

def test_throw_2(self): cricket = Cricket() cricket.throw(18,2) self.assertEqual( cricket.score(18),2)

Page 6: Python Autotest pdc2008w

6

テストを実行する[c:\ut\darts]python ut1.py -v

test_throw (__main__.TestCricket) ... oktest_throw_2 (__main__.TestCricket) ... oktest_throw_2_1 (__main__.TestCricket) ... oktest_throw_3 (__main__.TestCricket) ... oktest_throw_mix_a2_b1 (__main__.TestCricket) ... oktest_throw_mix_all (__main__.TestCricket) ... ok

-------------------------------------------------------------Ran 6 tests in 0.001s

OK

OK

Page 7: Python Autotest pdc2008w

7

Subversion に保存する

.java.c

.py

コミット!

Page 8: Python Autotest pdc2008w

8

Buildbot に通知

Page 9: Python Autotest pdc2008w

9

自動テスト

[c:\ut\darts] python ut1.py......---------------------------------------------Ran 6 tests in 0.000s

OK

Page 10: Python Autotest pdc2008w

10

テスト結果を Web で閲覧

Page 11: Python Autotest pdc2008w

11

時々 UT せずにコミット

まあ動くよね

Page 12: Python Autotest pdc2008w

12

自動テスト失敗 ....

FAIL: test_throw_mix_all (__main__.TestCricket)----------------------------------------------------Traceback (most recent call last): File "ut1.py", line 66, in test_throw_mix_all self.assertEqual(AssertionError: 3 != 4

----------------------------------------------------Ran 6 tests in 0.018s

FAILED (failures=1)

Page 13: Python Autotest pdc2008w

13

エラーだと通知やパトランプ

Powered byGainer

Page 14: Python Autotest pdc2008w

14

Demo

Page 15: Python Autotest pdc2008w

15

もうちょっと詳しく

Page 16: Python Autotest pdc2008w

16

Buildbot とは- 継続的インテグレーション ( ビルド・コンパ

イルの自動化 )- Python で書かれている

- Python が動作する -> BuildBot も動作

類似ソフト- Tinderbox (http://www.mozilla.org/tinderbox.html)

- CruiseControl (http://cruisecontrol.sourceforge.net/)

Page 17: Python Autotest pdc2008w

17

Buildbot の構成http://buildbot.sourceforge.net/manual-0.7.5.html

Page 18: Python Autotest pdc2008w

18

Buildbot 実行の流れ1. ビルド実行のトリガー

– SVN/CVS のコミット– 前回のテストから N 時間たった

2. マスターが各スレーブにビルド命令を出す3. 各スレーブがマスターにビルド結果を報告4. マスターが各スレーブのビルド結果を報告

– メール– Waterfall( ブラウザー )

Page 19: Python Autotest pdc2008w

19

ビルド実行のトリガー• バージョン管理システムの変更

– Subversion– CVS– Darcs– Mercurial– Arch/Bazaar– P4

• スケジューリング– 周期的– Cron 風– …

Page 20: Python Autotest pdc2008w

20

ビルドステップ1. master.cfg ファイルに記述2. 中身は Python プログラム3. スレーブごとにビルド内容やビルドトリ

ガーを設定することも可能• ソースコードの階層が変更された• 開発の活発さが異なる場合などに便利

Page 21: Python Autotest pdc2008w

21

ユースケース 1Python( 本体 ) の場合

1. ソースコードのアップデート (trunk/branch) 2. configure3. make4. make test

... を様々なハードウェア(Windows/POSIX|32/64 bit) で実行

Page 22: Python Autotest pdc2008w

22

ユースケース 2Web アプリの場合

1. ソースコードのアップデート (trunk/branch)2. ユニットテスト3. ファンクショナルテスト4. テスト失敗時にはメール送信

( エラーログを添付 ) を定期的 (2 時間間隔 )に Windows/Linux で実行

Page 23: Python Autotest pdc2008w

23

Buildbot 使ってるツール類

- Buildbot, Twisted, ILM, Free Geek, Mono, SpamAssassin, Boost, Zope, OpenID, Python, KDE, Enfold Systems, Subversion, GHC, OpenOffice, Jython, OpenSG, NUT, GNOME, Gentoo Linux, wxWidgets....http://buildbot.net/trac/wiki/SuccessStories

- Python の buildbot ページhttp://www.python.org/dev/buildbot/all/

Page 24: Python Autotest pdc2008w

24

参考リンク- Buildbot: 本家

http://buildbot.net/- Buildbot: マニュアル (0.7.5)

http://buildbot.net/repos/release/docs/buildbot.htmlユーザーマニュアル

- Buildbot: build/test automationhttp://buildbot.sourceforge.net/PyCon-2003/buildbot.html

BuildBot の概要 (PyCon 2003 の発表資料 )

Page 25: Python Autotest pdc2008w

25

Selenium

Page 26: Python Autotest pdc2008w

26

Selenium- ウェブアプリ用自動テスト用フレーム

ワーク- JavaScript でブラウザを制御- ThoughtWorks が開発→オープンソース化

• Selenium Core• Selenium IDE• Selenium RC

Page 27: Python Autotest pdc2008w

27

マルチ OS ・ブラウザ対応

• OS–Windows–Mac–Linux

• ブラウザ– IE–Firefox–Opera–Safariなど

Page 28: Python Autotest pdc2008w

28

テスト実行画面

テスト実行エリア

テスト操作テストケーステストスイート

Page 29: Python Autotest pdc2008w

29

Selenium テストの書き方 – テストケース

HTML テーブルでブラウザの動作と期待される結果を表現

コマンド一覧http://www.openqa.org/selenium-core/reference.html

Page 30: Python Autotest pdc2008w

30

Selenium IDE- Firefox Extension

– OS に依存しない– インストールが簡単

- Selenium 用テストコードの作成・生成ツール

- Selenium Core の実行環境

Page 31: Python Autotest pdc2008w

31

SeleniumIDE でテストコード作成・生成

• ブラウザの操作をレコードし、 Selenium コマンドに変換

• コマンドの追加・編集• 作成したテストケースをその場で実行で

きるリプレイ -> 編集というサイクル

• サーバーにアップロードさせる必要もない

Page 32: Python Autotest pdc2008w

32

Selenium RChttp://www.openqa.org/selenium-rc/tutorial.html

Page 33: Python Autotest pdc2008w

33

Selenium Server の役割• クライアントからコマンドを受け取る• ブラウザのプロキシサーバー

Page 34: Python Autotest pdc2008w

34

Selenium RC クライアント

さまざまな言語に対応( 各言語のテストフレームワークの上にドラ

イバーは作成されている )- Java(JUnit)- C#(NUnit)- Perl(Test::More)- Python(unittest)- PHP(PHPUnit)

Page 35: Python Autotest pdc2008w

35

例 :Python ドライバ>>> sel = selenium("localhost", 4444, "*firefox",>>> "http://www.google.com/webhp")>>> sel.start()>>> sel.open("http://www.google.com/webhp")>>> sel.type("q", "hello world")>>> sel.click("btnG")>>> sel.wait_for_page_to_load(5000)>>> sel.get_title()hello world - Google Search

Page 36: Python Autotest pdc2008w

36

参考リンク- Open QA

http://www.openqa.org/

Selenium-Core, Selenium-RC など

- Selenium 徹底活用http://labs.gree.jp/presentation/20060824/slides/selenium.html

Selenium IDE 作者による Selenium の紹介資料

Page 37: Python Autotest pdc2008w

37

Buildbot with Trac

• Using Buildbot and Trac togetherhttp://buildbot.net/trac/wiki/BuildbotAndTrac

発表予告していましたが今回は時間切れでした ...

この資料の元を作成してくれた同僚のジョージさん、ありがとう!