-
第1章 テストしづらい部分を分割する
- 1.1 題材
- 1.2 最初のテストコード
- 1.3 仕様を理解してテストを作る
- 1.4 別のテストケースを作る
- 1.5 依存関係を見つける
- 1.6 依存関係を削除する(その1)
- 1.7 依存関係を削除する(その2)
- 1.8 ここまでのまとめ
- 1.9 実装コードをリファクタリングする
- 1.10 要件が間違っているところを、テストケースを追加しながら修正する
- 1.11 実装コードを分割するために、一部分をメソッド化する
- 1.12 まだ確認していないロジックの確認を行う
- 1.13 まとめ
-
第2章 ロジックを分解して整理する
- 2.1 題材
- 2.2 とりあえずテストを実行する
- 2.3 次のテストケースを加える
- 2.4 switch文部分の実装コードをリファクタリングする
- 2.5 別部分のロジックに注目する
- 2.6 クラスを新たに作成する
- 2.7 再び実装部分のリファクタリングをする
- 2.8 残りの実装部分をリファクタリングをする
- 2.9 責務を持つクラスにロジックを移動させる
- 2.10 まとめ
-
第3章 要件を元に責務ごとにロジックを分割して整理する
- 3.1 題材
- 3.2 とりあえずテストを実行する
- 3.3 最初のメソッド切り出し
- 3.4 実装コードを理解していきながらテストケースを追加する
- 3.5 早期returnを目指し、ロジックをシンプルにしていく
- 3.6 否定系のif文をなくす
- 3.7 外側と内側にあるif文を入れ替える
- 3.8 商品ごとにif文をまとめる
- 3.9 それぞれの種類毎で処理ロジックをまとめて、インタフェース化を検討する
- 3.10 Factory Methodパターンを用いる
- 3.11 クラスの責務から考えたロジックの移動
- 3.12 機能追加の対応
- 3.13 まとめ
- 付録A IDEの入力補助の画像解説
- 付録B 参考文献
- おわりに
テストコードの注入から始めるレガシーコードのリファクタリング
レガシーコードに立ち向かう一歩目は、とりあえずテストを書いてみることだ
レガシーコードのリファクタリングの書籍の多くは、テストコードの大切さを説いている一方で、肝心のテストコードはあまり記述されないことが多いです。
これにより、あたかも「最初の作業として、テストコードをたくさん作る必要がある」と思わせてしまい、リファクタリングをするためのテストコードの作成に挫折してしまう事態を生み出しているように感じています。
そこで本書籍では、テストコードを少しずつ注入していきながら、レガシーコードに立ち向かう方法を、実際のテストコードを記載しつつ説明していきます。
また、一部題材については、実際にライブコーディングを行っている様子を収録したビデオも付いています。
The author is letting you choose the price you pay for this book!
レガシーコードのリファクタリングの書籍の多くは、テストコードの大切さを説いている一方で、肝心のテストコードはあまり記述されないことが多いです。
これにより、あたかも「最初の作業として、テストコードをたくさん作る必要がある」と思わせてしまい、リファクタリングをするためのテストコードの作成に挫折してしまう事態を生み出しているように感じています。
そこで本書籍では、テストコードを少しずつ注入していきながら、レガシーコードに立ち向かう方法を、実際のテストコードを記載しつつ説明していきます。
また、一部題材については、実際にライブコーディングを行っている様子を収録したビデオも付いています。
About
About the Book
本書籍では、レガシーコードに対しての最初の一歩を踏み出したいと考えている人に向けて書いた本になります。その際、テストコードの記述にも重点をおきながら、レガシーコードをリファクタリングする過程を説明しています。
本書籍では下記のような人を想定読者としています。
- テスト駆動開発(以下、TDD)を知っている
- レガシーコードやリファクタリングとは何か知っている
- 実際の現場でレガシーコードと出会っている
- レガシーコードに対してリファクタリングを行う時に、まず何から手を付ければ良いのか分からない
- 今後、自分がレガシーコードを作らないように心がけたい
本書籍を読み、写経することで、下記の 2 点が身につきます。
- 少しずつテストケースを追加して改善していく方法を実感する
- 苦しくないリファクタリングの方法を学ぶ
本書籍では Java および JUnit5 を用いて解説していきますが、基本的な考え方はどの言語でも似ていると考えていますので、読者の皆さんの言語に置き換えて読むことが可能です。
また、本書籍を購入していただいた方には、第3章で扱っている「要件を元に責務ごとにロジックを分割して整理する」のリファクタリングの様子を収めたライブコーディングのビデオも付いてきます。
Price
Pick Your Price...
Minimum price
$10.00
$15.00
You pay
$15.00Author earns
$12.00Author
About the Author
Yuya Kazama
After graduating, he joined an internal tool development team for 2 years and gained experience in design and development. 4 years later, he worked as a QA for test automation and process improvement.
Currently, he is participating in the launch team of QA, and is coaching how the QA team work with a small test base.
And he is now educating ourselves on the importance of creating quality from the upstream process in parallel with his daily work.
新卒から2年間、社内ツールの開発チームに参画し設計・開発の経験を積み、その後の4年はテスト自動化やプロセス改善など、QAとして従事した。
現在は、QAの立ち上げチームに参画し、テストベースが少ない状態からQAチームが活動できる体制を整備・啓蒙している。
また、普段の業務と並行して、上流工程から品質を作り込むことの大切さを社内外に啓蒙中。
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.