Skip to Content
テスト駆動開発を学ぶ
book

テスト駆動開発を学ぶ

by Saleem Siddiqui
May 2025
Intermediate to advanced
280 pages
3h 35m
Japanese
O'Reilly Media, Inc.
Content preview from テスト駆動開発を学ぶ

第1章. お金の問題

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

複雑さの向こう側にあるシンプルさには命を捧げる。

オリバー・ウェンデル・ホームズ・ジュニア

開発環境は整った。この章では、テスト駆動開発をサポートする3つのフェーズを学ぶ。 そして、テスト駆動開発を使って最初のコード機能を書いてみよう。

レッド・グリーン・リファクターTDDの構成要素

テスト駆動開発は、3段階のプロセスに従う:

  1. 。失敗するテスト(コンパイルの失敗の可能性も含む)を書く。テストスイートを実行して、失敗したテストを検証する。

  2. グリーンだ。テストをグリーンにするのに十分な本番コードを書く。これを検証するためにテストスイートを実行する。

  3. リファクタリング。コード臭を取り除く。重複、ハードコードされた値、言語イディオムの不適切な使用(例:組み込みのイテレータの代わりに冗長ループを使う)などによるものである。リファクタリング中にテストが壊れてしまった場合は、このフェーズを終了する前に、テストをグリーンに戻すことを優先する。

これが、図1-1に示すRGR(red-green-refactor)サイクルである。このサイクルの3つのフェーズは、テスト駆動開発の本質的な構成要素である。本書で開発するコードは、すべてこのサイクルに従う。

The Red Green Refactor (RGR) cycle. Red: write a failing test. Green: write just enough production code to pass the test. Refactor: remove code smells, e.g. duplication or poor design, without adding new features.
図1-1. レッド-グリーン-リファクターサイクルは、テスト駆動開発の基盤である。
重要

レッド-グリーン- リファクタサイクルの3つのフェーズは、TDDの本質的な構成要素である。

何が問題なのか?

私たちにはお金の問題がある。いや、ほとんどの人が抱えているような「お金が足りない」という問題ではない!どちらかというと、「お金を管理したい」という問題だ。

複数の通貨で資金を管理するためにスプレッドシートを作成する必要があるとしよう。

在庫 証券取引所 株式 株価 合計

IBM

NASDAQ

100

124 米ドル

12400 米ドル

BMW

ダックス

400

75 ユーロ

30000ユーロ

サムスン

KSE

300

68000ウォン

20400000ウォン

このスプレッドシートを作るには、いずれかの通貨の数字に対して簡単な算術演算をする必要がある:

5米ドル×2=10米ドル

10ユーロ×2=20ユーロ

4002 krw / 4 = 1000.5 krw

通貨間の換算もしたい。例えば、1ユーロを両替すると1.2米ドルになり、1米ドルを両替すると1100ウォンになる:

5米ドル+10ユーロ=17米ドル ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

はじめての知識グラフ構築ガイド

はじめての知識グラフ構築ガイド

Jesus Barrasa, Jim Webber
初めてのGraphQL ―Webサービスを作って学ぶ新世代API

初めてのGraphQL ―Webサービスを作って学ぶ新世代API

Eve Porcello, Alex Banks, 尾崎 沙耶, あんどうやすし
ユーザーストーリーマッピング

ユーザーストーリーマッピング

Jeff Patton, 川口 恭伸, 長尾 高弘

Publisher Resources

ISBN: 9798341650992