Pragmatic Unit Testing In Java With Junit (Pragmatic Programmers) (英語) ペーパーバック – 2004/9/1
Kindle 端末は必要ありません。無料 Kindle アプリのいずれかをダウンロードすると、スマートフォン、タブレットPCで Kindle 本をお読みいただけます。
Presents a guide to unit testing with the JUnit library in Java along with providing information on writing code, detecting and fixing problems, testing pieces of code, and testing with a team.
Andy Hunt and Dave Thomas have more than 50 years combined experience, developing software for clients around the world. For the last 10 years they've been working together as The Pragmatic Programmers, helping clients write software and improve their development processes. They are authors of the best-selling The Pragmatic Programmer, and have written several other books. They speak at conferences globally, and are editors of IEEE Software's "Construction" column.
The book gives a general introduction to the whys and wherefores of unit testing and then uses a good example to introduce JUnit as a mechanism for carrying out these tests. This is followed by various chapters that look into what you should test and when and where, etc. In this respect it covers much of the ground on unit testing and does it well but the truth is that there isn't all that much to cover; to the extent that the authors can even provide a one page at-a-glance summary of all their main points at the back of the book. This is fine and as an introductory text I would recommend the book.
On the other hand, there are a number of areas in unit testing that always present problems for developers. For instance:
How should private methods be tested? This is mentioned in passing but not really addressed.
Where should tests be stored? Some options are presented but their advantages and disadvantages barely mentioned.
How can systems such as databases or networks be simulated for test purposes? There is a short chapter on simple Mock Objects but after presenting a small example they conclude "and that's all there is to mock objects" and the rest of the chapter barely covers anything more.
In summary, the book is a good (if verbose) introduction for beginners but is of limited value for those who are already familiar with JUnit and are looking for a book that tackles the more difficult areas.
While JUnit and Mock Objects are introduced in the text, the main focus is on developing insight into the philosophy of pragmatic unit testing. Most developers have a vague understanding of the why and how, but what do their results really mean? Are they sufficient to determine that the code is correct? How does the developer know?
With anecdotes and clear examples, the authors help to clear the fog. Just as important, they dispel many of the testing myths and explode the excuses that are offered for not unit testing. Resistance will frequently come developers, but also from management thinking that developing test code will add time to the project instead of saving it.
A side-effect of developing unit tests is that they add another layer of code that must be managed. Do you need tests for your test? Where does it end? Again the pragmatic programmers provide poignant pointers to managing the tests themselves.
One of the pragmatic programmer commandments must be "Be brief". In less than 160 pages, this slim volume covers a lot of ground. For a project technical lead, several copies for your team to read may be a solid investment. Be sure to make a poster-sized version of the "Pragmatic Unit Testing: Summary" page from the book for the wall behind your desk.