4.7.4 テストの作成
まずはテストに関するルールとガイドラインを順番に見ていきましょう。
- テストのための PHP ファイルは、app/tests/cases/フォルダ に設置します。
- ファイル名は「.php」ではなく「.test.php」で終わらなければいけません。
- テストのためのクラスは、CakeTestCase または CakeWebTestCase を拡張したものでなければなりません。
- テストのためのメソッド、つまりアサーション(assertion)の名前は、「test」で始まらなければなりません。たとえば、「testPublished()」といったようにです。
テストケースを作成したら、http://ドメイン名/CakePHPのフォルダ/test.php(設定に依る)をブラウズし、「App」の「Test Cases」をクリックし、作成したファイルへのリンクをクリックすることで実行できます。
4.7.4.1 CakeTestCase Callback Methods
このセクションには保留されている変更があります. More information about translations
If you want to sneak in some logic just before or after an individual CakeTestCase method, and/or before or after your entire CakeTestCase, the following callbacks are available:
start()
First method called in a test case.
end()
Last method called in a test case.
startCase()
called before a test case is started.
endCase()
called after a test case has run.
before($method)
Announces the start of a test method.
after($method)
Announces the end of a test method.
startTest($method)
Called just before a test method is executed.
endTest($method)
Called just after a test method has completed.
