Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
class APITestCase(TestCase): @responses.activate def test_api(self): import api # setup responses.add( responses.GET, 'https://example.com/api/v3/users', status=200, body="[{'user': {'id': 1, 'username': 'test'}}]", content_type="application/json", ) # test api.get_users() assert responses.calls[0].request.method == 'GET' assert responses.calls[0].request.url == 'https://example.com/api/v3/users'
テストを書くときに、外部の HTTP API を叩く処理が組み込まれている場合は、何かしらモックが必要です。 どう書くのがスマートなのか良くわからないので色々試してみる 準備するモノ python 2.7.x mock simplejson requests nose covarage テストのデファクト あまりまとまってるのがないので、まとめておきます。 テストランナーは nose または py.test nose はプラグインがステキ py.test はなにやら色々嬉しい事があるらしい モック/スタブは mock テストは unittest (unittest2) カヴァレッジは covarage ? これは良くわからず、基本 Jenkins に食べさせらるタイプで出力できればおk この辺が今のところデファクトでしょうか、ご意見お待ちしております。 mock patch を使うと綺麗に
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く