Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
インフラエンジニアが考えてみた Mockの使いどころ
Search
gkzz
July 25, 2019
Programming
780
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
インフラエンジニアが考えてみた Mockの使いどころ
pythonのmockというテストフレームワークについて
gkzz
July 25, 2019
More Decks by gkzz
See All by gkzz
MagicPodで始めるがんばらない回帰試験の自動化/Automated Regression Testing Journey with MagicPod
gkzz
0
4.2k
#JTF2021W_D VimiumではじめるよちよちVimmerライフ / Vimmer beginners start with Vimium
gkzz
1
2.5k
What I Need to Do Before Promoting Automation
gkzz
0
130
StackstormというIFTTT的なツールをDockerコンテナに載せた小話
gkzz
0
1.1k
QuickStartToGAS
gkzz
0
370
About Our House
gkzz
0
77
Other Decks in Programming
See All in Programming
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
430
iOSDC2026登壇資料.pdf
riofujimon
0
190
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
310
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.1k
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
360
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
380
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
4k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
450
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
260
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Design in an AI World
tapps
1
330
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
The Curse of the Amulet
leimatthew05
3
15k
Deep Space Network (abreviated)
tonyrice
0
320
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
GitHub's CSS Performance
jonrohan
1033
470k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
My Coaching Mixtape
mlcsv
0
330
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Transcript
インフラエンジニアが考えてみた Mockの 使いどころ 若手サーバエンジニア・サーバ業界関係者交流会2019 in Tokyo 株式会社エーピーコミュニケーションズ インフラエンジニア 玉木岳爾
1/18. はじめまして 名前: 玉木岳爾 @gkzvoice 会社: 株式会社エーピーコミュニケーションズ 業務: ネットワーク環境構築の自動化 家:
ギークハウス新宿
2/18.これからお話しすること ・苦労していること ・mockについて ・使いどころ ・サンプルコード ・留意点
3/18.苦労していること ②想定外の出力結果 ①機器へ都度接続
None
そこで、 mock の登場じゃ。
6/18.mockとは ・unittest.mock はPython におけるソフトウェアテストのためのライブラリ ・テスト中の システムの一部をモックオブジェクトで 置き換え、それらがどのように使われるかをアサートすることができる ・デモ動画 master/docs/demo/develmock.gif 出所:
unittest.mock --- モックオブジェクトライブラリ — Python 3.7.4 ドキュメント
7/18.使いどころ コマンドの生成 コマンドを実行 正常結果取得 結果の判定 起きにくい エラーの再現 ってどうやれば?
コマンドの生成 コマンドを実行 正常結果取得 結果の判定 8/18.使いどころ コマンドを実行 エラー結果取得 モジュールパス(<filename.class.method>)に patchをあててMockオブジェクトに差し替える @patch(<filename.class.method>,
return_value=’Error Test’)
9/18.サンプルコード
self.challenge( current_conts) return current_conts current_conts = 1 current_conts += 1
conts % 2 == 0 return True return False challenge( self, conts) main() Sample Class current_conts = 2 continue break while True
11/18.サンプルコード(mockなし)
12/18.サンプルコード(mock)
13/18.サンプルコード(mock)
None
15/18.留意点 テストの目的を意識しないと、 テストが”デキレース”に
コマンドの生成 コマンドを実行 正常結果取得 結果の判定 16/18.使いどころ(再掲) コマンドを実行 エラー結果取得 モジュールパス(<filename.class.method>)に patchをあててMockオブジェクトに差し替える @patch(<filename.class.method>,
return_value=’Error Test’)
17/18.まとめ ・mockはクラスやメソッドを差し替えるもの ・使いどころ 再現しにくい事象が起きたときにプログラムは機能するかどうか の検証 ・留意点 mockで差し替えるものばかりになっていないか
おしまい ソースコード https://github.com/gkzz/mock_sample
補足
補足.業務内容 True/False? True/False? 切り戻し コマンド1 コマンド2 ネットワーク環境構 築の自動化!