Generic open source automation framework for acceptance testing, acceptance test driven development (ATDD), and robotic process automation (RPA).
単体テストガイドライン¶ Pylons プロジェクトは、このドキュメントの元となった Tres Seaver によって書かれた Avoiding Temptation: Notes on using unittest effectively に倣ったユニットテスト教義をかなり厳格に守っています。 Note このドキュメントは、ほとんど排他的に 単体 テストを扱います。 結合テストまたは機能テストに対しては私たちは特別の教義を持っていません。 しかし、下記の tips の多くはその文脈でも再利用できます。 悪い単体テストを避けるための tips¶ ある人々は “don’t repeat yourself” をむやみに信じてきました (drink the KoolAid): 私たちは、ほとんどの場合にはコードの繰り返しをしないことが 美徳であることに同意します。しかし、単体テストコードはその例
pyassert is an assertion library for the Python programming language. Introduction Assertions are used in automated tests to verify that a given piece of code behaves as expected. pyassert aims to provide assertions with provide rich functionality: common assertions should be expressed easily good readability: assertions should be easy to read and easy to understand to enhance the overall underst
Goals The goals of the kind of testing outlined here are simplicity, loose or no coupling, and speed: Tests should be as simple as possible, while exercising the application- under-test (AUT) completely. Tests should run as quickly as possible, to encourage running them frequently. Tests should avoid coupling with other tests, or with parts of the AUT which they are not responsible for testing. De
Seriously. This tutorial badly needs updating. Everything is in the book, and much, much more. It's also written in step-by-step tutorial form, it uses the latest django, and it really is free. No catch. What's the approach? Test-First! So, before we're allowed to write any real production code, we write some tests. We start by writing some browser tests - what I call functional tests, which simul
Djangoでユニットテストを書く際にテストクライアントを使うことができますが、これはurls.pyを用意しないと使えません。 しかし、ビュー関数のみをテストする場合、Requestクラスのオブジェクトが必要になります。 django.test.client.RequestFactoryを使えば、GETやPOSTメソッドのRequestオブジェクトを簡単に生成できます。 試したバージョンは、Python2.7.2、Django1.4。 views.py from django.http import HttpResponse def my_view(request): return HttpResponse("OK") このmy_view関数をテストする。 tests.py from django.test import TestCase from django.test.client i
xxxx.pyに直接以下のようにコードを書いているのだと想定します。 import sys arg = sys.argv[1] count = raw_input("count? ") # write some code and set 'result' value print result これは以下のように書けます。 import sys def run(argv, count): # write some code and set result value return result def main(): x = raw_input("count? ") result = run(sys.argv, x) print result if __name__ == '__main__': main() この様に書かれたxxxx.pyには3つのメリットがあります。 直接実行すれば変更前と
$ pip install nose $ pip install mock $ pip install coverage $ pip install tox
pytest *1 に関連して tox も一緒に覚えておくと良さそうです。 @t2y @methane 少し前からtox + py.test が鉄板な気がしますねえ 2012-02-07 20:50:23 via twicca to @t2y tox については id:Ehren の入門記事が分かりやすいです。 Pythonでのテストツールtox入門 - Keep on moving 複数の Python バージョン毎に virtualenv で仮想環境を作成して、そこに自分のパッケージと必要なライブラリ等をインストールして、それぞれのバージョン毎にテストをまとめて実行してくれます。例えば、Python 2/3 の両対応を考えたときに、自分で環境を切り分ける手間隙を軽減できて、かなり便利です。ここで言う Python 2/3 両対応は 2.6/2.7 と 3.x の対応を指します *2 。
pytest で初めてテストを書いてみました。 今度こそ帰るー、py.test を使って初めてテストを書いた、評判通りすごく良い 2012-02-07 19:48:52 via TweetDeck @t2y noseと比べた感想とか聴きたいです。 2012-02-07 19:55:04 via web to @t2y @methane @t2y テストがこけたときまともなレポートをはくのがpy.testのいいところ 2012-02-07 19:56:34 via twicca to @methane nose と比べて、データ駆動テスト *1 *2 の違いが大きかったのでまとめてみます。 準備 以下の素数判定を行うテスト対象関数があるとします。 PRIME = {2: True, 3: True, 4: False, 5: True, 6: False, 7: True} def is_p
mock を使ったニットテストの、シンプルなシーンをまとめました。例として「Twitter アカウントのスクリーンネームを指定し、そのアカウントの最新のツイートの内容を取得する」という機能を実装する場合を考えます。 まず、簡単にユニットテストを書けるような場合から考えます。create_user_timeline_url() 関数を定義し、Twitter アカウントの screen_name を渡すと、そのアカウントのつぶやきを取得するために URL が返される、としましょう。たとえば Twitter アカウントのスクリーンネーム wozozo を渡すと、 http://twitter.com/statuses/user_timeline/wozozo.json が返ってくることを確認します。 実装とテストは以下のようになります。URL のテンプレートを定数にしたほうがいいとかありますが、
単体テストというのは、本来、あるコンポーネントの依存先に影響されないように、対象をテストします。が、これまでは比較的てきとーで、依存先のテストが通っていれば、依存先を完全に分離せずにやってきました。 これには2つ問題があって、(1) そもそもそれは単体テストではない、(2) 依存先が外部だったらどうするんだ、と。例えば、Twitter からタイムラインをとってくる、とかですね。 def get_user_timeline(user) """タイムラインをとってきて、辞書で返す""" twitter = Twitter() response = twitter.get_timeline(user.id, user.access_token) timeline = [{'text': tweet.text} for tweet in response['tweets']] return tim
at·test /əˈtɛst/ To affirm to be correct, true, or genuine. Attest is a test automation framework for Python emphasising modern idioms and conventions. from attest import Tests math = Tests() @math.test def arithmetics(): """Ensure that the laws of physics are in check.""" assert 1 + 1 == 2 if __name__ == '__main__': math.run() Features¶ Collect tests using decorators instead of matching names aga
pythonのモックとしてminimockというライブラリがある。 日本語のドキュメント・ブログが見当たらないので使い方をここに書いておく。 minimockを構成するモジュール mock関数 -- モックを当てる。 restore関数 -- 当てたモックを解除する。 Mockクラス -- mockより詳細にモックを当てるために使うオブジェクト。 mock関数とrestore関数でモックを当てる・解除するというのはわかりやすい。 しかし、複雑なケースではMockオブジェクトを使う必要があるのでここで説明する。 あと、minimockを使う上ではまりやすい点を書く。 基本的な使い方 minimockの基本は モックに差し替えるモジュールをインポートする。 mock関数を呼ぶ。或いはMockインスタンスを代入する。 使い終わったらrestoreで戻す。 である。 例えば、以下のphilosop
はじめに nose の組み込みプラグインを利用するとテストで実行された時のカバレッジを取得できます。 テスト実行時のカバレッジを取得できるので、テストでカバーできていない範囲など確認できます。 カバレッジを取得する nose と python-coverage がインストールされている必要があります。 nosetests コマンド実行時に、 --with-coverage オプションを付けることでカバレッジを取得できます。 --cover-tests を付与すると実行されたテスト用コードのカバレッジを取得できます。 インストール手順 $ easy_install -ZU nose $ easy_install -ZU coveragenose からのカバレッジ取得し、HTMLに変換する。 $ cd myproject $ nosetests -v --with-coverage tests
Python Hack-a-thon 5 ハンズオン 中級コース¶ DocTestで覚えるTDDのリズム¶ 担当: 清水川 このハンズオンでは、以下の内容について体験していきます。 PythonのDocTestを使ってみよう TDDをDocTestでやってみよう 環境¶ WindowsでもMacでもUnix系でも。 Pytohn2.6~3.x ただしこの資料は2.6しか動作保証しません Test Driven Development について¶ Test Driven Development = TDD, 日本語で言うと テスト駆動開発 です。 TDDはその名の通り、テストで開発を駆動する手法で、簡単に言うと以下の ステップで実装を進めていきます。 テストコードを書く テストを実行する(実装前なのでエラーになる = RED) テストコードを通す実装をする(fake it) テストを実行する
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く