0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Test Double, Dummy, Stub, Spy, Mock の違いは?

Posted at

はじめに

呼び出すとコストがかかる処理やそもそもテスト環境で呼び出せない処理を「モックする」ことはよくある。ただ「モック」に関する用語が色々あってよくわからない 🤯

ねねっち

この記事は?

説明

Test Double, Dummy, Stub, Spy, Mock は並列なものというわけではない。階層構造になっている。

Test Double

カストロ
  • あるオブジェクトの代わりを演じる
  • double: 代役、影武者
    • 俳優の代わり: スタントダブル
    • 俳優の手の代わり: ハンドダブル
    • 俳優の身体の代わり: ボディダブル

Dummy

身代わり人形
  • 何もしない実装を持つテストダブル
    • メソッドが値を場合は null や 0 を返す
  • dummy: マネキン人形、模造品

Stub

きこりの切り株
  • メソッドが null や 0 ではなく、固有の値を戻すダミー
    • テストする経路に関数を仕向ける。
  • stub: (鉛筆などの) 使い残り、半券、切り株

Spy

image
  • 何が行われたかを記憶するスタブ
  • spy: スパイ、〜をひそかに調べる

Mock

あざ笑う
  • メソッドが null や 0 ではなく、固有の値を戻すダミー
  • 何が行われたかを記憶するスタブ
  • 何が期待されているかを把握し、その期待に基づいてテストを成功あるいは失敗させるスパイ
  • mock: 〜をあざ笑う、模擬の、偽の

参考

Web

書籍

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?