pylonsからnosetestsを勉強中
pylons pasterでcontrollerを作成するとtestsというディレクトリ下にcontroller毎のテスト用モジュールが作られる。
これをnosetestsでテストしていく。
自動生成されるtests/functional下のファイルはtest_[アクション名].pyとなっている。
> vi test_page.py
from kapiapp.tests import *
class TestPageController(TestController):
def test_index(self):
response = self.app.get(url(controller='page', action='index'))
# Test response...
このcontroller毎のモジュールに思うがまま書いていくっぽい。
pylonsで紹介されているテスト方法はプロジェクトをまるっとテストする方法
プロジェクトROOTで
> nosetests --with-pylons test.ini
でも、nosetestsのオプションでディレクトリ以下テスト、ファイル単体テストも出来る。
directory以下テスト -w
nosetests -w kapiapp/tests/my_test --with-pylons test.ini
エラー(例外)発見時pdb起動
nosetests -v --pdb --with-pylons development.ini kapiapp/tests/functional/test_page.py
nosetests -v --pdb-failures kapiapp/tests/functional/test_page.py --with-pylons test.ini
ファイル(モジュール)毎にテスト
nosetests -v kapiapp/tests/functional/test_page.py
ファイル名ごとにやる方が便利だあ。
参考URL
http://kapi.jp/kapi_blog/223
2009年04月13日