「今までテストを書いたことがないから、そろそろテストを書かなくては・・・」という、PHPUnitもテストのこともまだ知らないプログラマにとって、一番最初に欲しいのは「何から始めたらよいのか」を知るためのガイドです。 本書は、PHPUnitを使ったテストの書き方を、短時間で知るための小冊子です。これだけ読めば、PHPUnitでテストを書いていけるようになります。 本書が特徴的なのは、ユニットテストの形式的な書き方だけを単純に説明した本ではないということです。本書では、PHPUnitによるテストを、オブジェクト指向の原則に沿った、良いコードへリファクタリングしていくための道具、と位置づけています。その流れに沿って、必要最低限の基礎知識や、実際にありそうなサンプルコードで使い方が説明されています。モック(テストダブル)を使ったテスト、フィクスチャを使ったテスト、APIのテストといった対象ごとのP
Coverage 100%への道のり 1. --coverage-htmlして現状を確認 2. time()やmt_rand()などを使うコードもテスト 3. 複雑なオブジェクトを使うコードもテスト 4. ファイルシステムを使うコードもテストRead less
phpunitの本家はなかなかcomposerに対応していませんでした。なので、今までは本家のリポジトリではなく、EHER/phpunit-all-in-oneからphpunitをインストールするのが最も手軽でした。しかし、2012年8月13日に本家がcomposerをサポートしため、本家のリポジトリからインストールすることができます。 composer.json の "require-dev" は開発系の依存パッケージを指定するためのものです。一方、ここにはありませんが、通常の "require" はプロダクトの依存パッケージを指定するのものです。この2つを区別することで、開発環境やビルドマシンではComposerでPHPUnitをインストールでき、プロダクション環境ではPHPUnitをインストールしないように環境に応じて選択することができます。 ComposerでPHPUnitなどをイ
Symfonyはアプリケーションの機能テストのためにPHPUnit_Framework_TestCaseクラスを継承したWebTestCaseという抽象クラスを提供しています。機能テストを実行する基本的な方法は以下のようになります。 $ phpunit -c app src PHPUnit 3.6.8 by Sebastian Bergmann. Configuration read from /path/to/example/app/phpunit.xml.dist . Time: 0 seconds, Memory: 19.00Mb OK (1 test, 1 assertion)ここでphpunitコマンドの代わりにStagehand_TestRunnerのphpunitrunnerコマンドを使うと以下のようにエラーが発生します。これはMakeGoodでも同様です。 $ phpuni
VimからPHPUnitを実行する方法をまとめました。PHPUnitをquickrunで非同期実行し、結果にグリーンレッドの色をつけるまでを紹介します。 動作確認環境 Vim7.3quickrun0.5.1vimproc5.3PHP5.3.9PHPUnit3.6.7 目次 PHPUnitのインストール quickrunのインストール vimprocのインストール quickrunの設定 テスト結果にグリーン、レッドの色をつける PHPUnitのインストール 私は下記を参考にPHPUnitをインストールしました。 http://docs.symfony.gr.jp/symfony2/contributing/code/tests.html PHPのバージョンがPHPUnitに対応しており、PEARがインストールされていればうまくいくと思います。PHPUnitがうまくインストールできない場合は
PHPUnitでassertEquals()メソッドやassertSame()メソッドによる文字列のアサーションはごく一般的に行われていることです。例えば以下のコードを見てみましょう。 <?php class ExampleTest extends PHPUnit_Framework_TestCase { /** * @test */ public function 文字列を検証する() { $this->assertEquals('foo', 'bar'); } このテストを実行すると以下のような出力が得られます。 $ phpunit ExampleTest.php PHPUnit 3.6.4 by Sebastian Bergmann. F Time: 0 seconds, Memory: 5.75Mb There was 1 failure: 1) ExampleTest::文字列を
知ってる人は知ってると思いますが、ちょっと「えー!」な感じだったので。 TestCaseオブジェクトのsetUpメソッドやtearDownメソッドは、testメソッドが実行される前後にそれぞれ呼び出されます。つまり、それぞれ、testメソッド数分呼び出されます。これはよくドキュメントに書かれているので知っていると思います。 一方、コンストラクタはどうかというと。。。 背景 最近、テストの数(ファイル数、testメソッド数、assert数)が増えてきて、全テスト実行するのに30分以上かかっています。中には、DBに接続してSQLを実行して想定している結果が返ってくることをテストしていたり、HTTPリクエストを送信してステータスコードやContent-Typeヘッダ、レスポンスボディの中身が一致しているかどうかのテストなども行っているので、それなりに時間がかかるといえばかかるようになっています。
2. Hello! Mike Lively Lead Developer Selling Source, Inc. PHPUnit Contributor PHPUnit Database Extension A frequent inhabitant of #phpc http://digitalsandwich.com 4. PHPUnit - Advanced Features Mock Objects - A way to further isolate code while testing. Database Extension - A DBUnit port to allow creation of fixtures for database content. Selenium Integration - A gateway to integration testing. PH
皆さん, ユニットテスト書いてますか. TDD (テスト駆動開発) によるプログラミングは本当に楽しいものですが, コマンドをいちいち手動で実行するのは面倒ですよね. テストを自動化しているんだから, その実行も自動化したいですよね. この記事では, 私が仕事や趣味で使っている PHPUnit を例に, テストの実行の自動化について紹介します. PHPUnit の, としてはいますが, 他の言語で使えるテクニックもあります. なお, ここでの自動化は開発しながらの自動実行のことで, CI (継続的インテグレーション) の話は出てきません. その前に... 私の開発時のターミナルは以下のようになっています. [caption id="attachment_1298" align="alignnone" width="300" caption="開発時のターミナル"][/caption] GN
先日、「PHPでTDD&CIワークショップ」に行ってきました。 ノートに入れて持っていった PHPUnit が微妙に古かったりしてちょっと迷ったりして。それ以前に PHPUnit 自体をあまり使ってなかったりして。 ワークショップは、 TDD と CI (Jenkins) の二種類あり、 TDD に参加。 FizzBuzz を題材にテスト書いて、仮実装して、実装して、リファクタリングして、というのをペアプロしてみましょうというもの。会社ではペアを組む相手が居ないので、実のところペアプロ初体験でしたが、 @JP_tomo さんと組んでみました。 PHPUnit をごそごそいじっていて、正しい型で返ってきているか調べたいよねー、という話になり、型そのものをみるには assertInternalTypes() が使えるけど、 PHPUnit 3.4 では使えないねー、とか、 assertEqua
去る6月4日、第4回Symfony2勉強会でLT発表してきました。以下が発表資料です。 発表資料:「PHPUnitのMockObjectの紹介」(slideshare版)(PDF版) 僕だけSymfony2と何の関係があるの?という感じのタイトルでしたが、案外好評だったように思います。懇親会でも何人かに声をかけて頂いて、このあたりの話題は結構ニーズがあるんだなーと感じました。 スタブとモックの違いについては伝えるのが難しいかと思っていたのですが、伝わったよ、と言ってくれた人がいて、安心しました。ちなみに本文中で触れているMatrin Fowlerのブログ記事は下記です。 「Mocks Aren't Stubs」 発表中、Martin Fowlerはモックによるテストに懐疑的なようだ、という話を紹介しました。もう少し詳しく紹介すると、モックで「ふるまい」のテストを書くためには、どう実装するか
Loading… Flash Player 9 (or above) is needed to view presentations. We have detected that you do not have it on your computer. To install it, go here. PHPUnit Best Practices - Presentation Transcript PHPUnit Best Practices Sebastian Bergmann July 22 nd 2010 Hello! My name is Sebastian. Sebas tian Hello! My name is Sebastian … and this is what
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く