Railsの自動テストでデータベースにテストデータを投入する方法は2つあります。 FixturesとFactory Girlです。 前者がRails標準で、後者はGemパッケージとして提供されています。 前者はYAMLで、後者はRubyでデータを記述します。 私がRailsに出会った頃(2005年)にはFixturesしかありませんでした。その時は、こんな便利なものはないと感激しましたが、データベース構造やアプリケーションのロジックが複雑になるにつれYAMLファイルを保守するのに困難を感じるようになりました。その後、Factory Girlを知り、Fixturesを使うのをやめてしまいました。 最近知ったのですが、一昨年(2014年)に私がRailsでMinitestとFixturesを使い続ける7つの理由と題する英語のブログ記事が書かれて、ちょっと話題になったそうです。 RSpecの代わ
minitest には標準で mock や stub の機能が付いています。それらの挙動について学んだのでメモ。 コード例 下記のような Person クラスと Whisky クラスがあるとします。これらについて minitest の mock と stub を使ってテストを書いてみます。 class Person def eat(food) food.taste end def drink(whisky) whisky.alcohol.upcase end end class Whisky def alcohol # まだ実装されていない end end mock minitest では下記のように mock を書きます。 describe Person do subject { Person.new } describe '#eat' do it '引数にとったオブジェクトの #tas
Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and ease of use in the current mocking frameworks combined with a recent experience with Mockito for Java. A key conceptual difference in mocking between Phake and most of php mocking frameworks (ie: mock functionality in PHPUnit, PHPMock, and mock functionalit
こんにちは。前回のPhakeのモックでCakePHPをテスト コントローラ篇にもレスポンスが頂けて嬉しいです。天の声に耳を傾けていると(ただのエゴ・サーチです…)素敵なご指摘が聞けたので、改訂版として掲載します。予定していた「コンポーネント篇」は改訂版のおかげで不要になりました! 準備も少なくて済む画期的な方法です。 ControllerでPhakeモックを使いたいという背景については前回の記事をそのまま残しますのでご参照ください。 -- ※本記事ではCakePHPにPhakeを導入する手法について解説しています。Phake自体の使い方やPHPUnit標準モックとの比較は過去の記事にて紹介しています。 2段階のサブクラスを作成する 前回と同じく、CakePHPのControllerTestCaseから機能を拡張するためMyControllerTestCaseを作成します。abstract
140313追記: 以下の方法を使わずに更にシンプルに準備できる改訂版を掲載しました。以下は古い内容をそのまま載せています。 -- 前回のPhakeのモックでCakePHPをテスト モデル篇の続きです。PhakeはPHPUnit標準のモック機構と違いWhen, Verifyに分けて定義を記述できる点が特徴で、流れを追いやすく一行もシンプルで済む今おすすめのモック・フレームワークです。 さて、このPhakeをCakePHPのController Testで活用しようとすると、いきなり壁にブチ当たります。 CakePHPはPHPUnitを標準採用している 幸か不幸かCakePHPはPHPUnitを標準で採用しており、高い親和性で書けるのが特徴ですが、Phakeといった外部テスト・フレームワークの入る余地は少なくなっています。 どうにかPhake一本でControllerのモック化が出来ないもの
The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing. Most language environments now have frameworks that make it easy to create mock objects. What's often not realized, however, is that mock objects are but one form of special case test object, one that enables a different style of testing. In this article I'll explain how mock obje
A mock object can be useful to the software tester like a car designer uses a crash test dummy to simulate a human in a vehicle impact. In a unit test, mock objects can simulate the behavior of complex, real objects and are therefore useful when a real object is impractical or impossible to incorporate into a unit test. If an object has any of the following characteristics, it may be useful to use
This article is about test fixtures. For other uses, see Fixture (disambiguation). A test fixture is a device used to consistently test some item, device, or piece of software. Test fixtures are used in the testing of electronics, software and physical devices. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsour
モックオブジェクト(Mock Object)とは、ソフトウェアテスト時、特にテスト駆動開発、ビヘイビア駆動開発における代用の下位モジュールスタブの一種。スタブと比較して、検査対象のモジュールがその下位モジュールを正しく利用しているかどうかを検証するのに使われる。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く