- []
- []
PRADO 単体および機能テスト
PRADO 単体および機能テスト概要
最近のフレームワーク同様、
PRADOにもテスティングシステムは搭載されている。
symfonyの場合はlimeという自前実装のテスティングツールが装備されていたが、
PRADOはsimpletestとseleniumを利用する形。
Unit Testはsimpletestが、
Functional Testはsimpletest+selenumが担当する。
PRADO 単体および機能テスト準備
ジェネレータを用いてテストフレームワークを設置する。
$ /usr/local/lib/php/prado/prado-cli -t [Directory Path]
PRADO 単体(ユニット)テスト
/test/unitディレクトリに、
単体テストのテストケースコードを設置していく。
ファイル名に特別既定はない
/test/unit/exampleTextCase.php
<?php class exampleTextCase extends UnitTestCase { }
あとはテスト内容を記述していく。
サンプルはこんな感じか。
<?php // Stub objects and functions for test purposes class myObject { public function myMethod() { } } class exampleTestCase extends UnitTestCase { function testExample() { // get application $app = Prado::getApplication(); // success $this->assertEqual( 1, '1', 'the equal operator ignores type' ); $this->assertNotEqual( 0, 1, 'zero and one are not equal' ); $this->assertPattern( '/test\d+/', 'test01', 'test01 follows the test numbering pattern' ); $this->assertNoPattern('/test\d+/', 'tests01', 'tests01 does not follow the pattern'); $this->assertIsA('foobar', 'string', "'foobar' is a string"); $this->assertIsA(new myObject(), 'myObject', 'new creates object of the right class'); // fail $this->assertIdentical( 1, '1', 'type mismatch integer and string' ); } }
実行結果
$ /usr/local/lib/php/prado/prado-cli test /home/project/ Command line tools for Prado 3.1.0. ** Loaded PRADO appplication in directory "protected". Running unit tests in directory "tests/unit": 1) type mismatch integer and string at [/home/project/tests/unit/exampleTest.php line 23] in testExample in exampleTestCase in /home/project/unit/exampleTest.php FAILURES!!! Test cases run: 1/1, Passes: 6, Failures: 1, Exceptions: 0
テストは7つ行っているが、
うち1つが[FAILURES!!!]と弱々しく表示されている。
PRADO 単体(ユニット)テスト 関連リンク
- ブックマークショートカット
framework/prado/testing.txt · 最終更新: 2007/07/27 19:01 by dozo