SummaryEffective Unit Testing is written to show how to write good tests—tests that are concise and to the point, expressive, useful, and maintainable. Inspired by Roy Osherove's bestselling The Art of Unit Testing, this book focuses on tools and practices specific to the Java world. It introduces you to emerging techniques like behavior-driven development and specification by example, and shows you how to add robust practices into your toolkit.About TestingTest the components before you assemble them into a full application, and you'll get better software. For Java developers, there's now a decade of experience with well-crafted tests that anticipate problems, identify known and unknown dependencies in the code, and allow you to test components both in isolation and in the context of a full application.About this BookEffective Unit Testing teaches Java developers how to write unit tests that are concise, expressive, useful, and maintainable. Offering crisp explanations and easy-to-absorb examples, it introduces emerging techniques like behavior-driven development and specification by example.Programmers who are already unit testing will learn the current state of the art. Those who are new to the game will learn practices that will serve them well for the rest of their career. Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book. About the AuthorLasse Koskela is a coach, trainer, consultant, and programmer. He hacks on open source projects, helps companies improve their productivity, and speaks frequently at conferences around the world. Lasse is the author of Test Driven, also published by Manning.What's InsideA thorough introduction to unit testingChoosing best-of-breed toolsWriting tests using dynamic languagesEfficient test automationTable of ContentsPART 1 FOUNDATIONSThe promise of good testsIn search of goodTest doublesPART 2 CATALOGReadabilityMaintainabilityTrustworthinessPART 3 DIVERSIONSTestable designWriting tests in other JVM languagesSpeeding up test execution
A nice book on unit testing. Even though written for Java developers, I believe most developers with only a smattering of Java can understand most of the first two parts of the book, since it carries across to any xUnit framework for any programmming language x of comparable power (say Python or C#).
Chapter one can be used to motivate the newcomer to unit testing, while chapter two is a well-written and stimulating overview of what is to come in the following chapters.
Chapter three, which ends the first part of the book, is an excellent overview of test doubles (stubs, fake objects, test spies and mock objects), leaving out only test dummies, the simplest kind of test doubles in Meszaros´ well-known proposal, and, to be honest, no great loss.
Part two is where most of the meat of the book is. It is a catalog on unit test refactorization techniques, structured into three chapters, one on techniques improving test readability, one improving test maintainability and the third, the weakest of the three, on improving comment trustworthiness.
The third part of the book is a grab-bag of topics. Chapter 7 on testable design kicks in with an excellent section on how SOLID principles relate to testability. After that, the non-Java developer will tend to skim over the very Java-specific guidelines for testable design, writing tests in other JVM languages (chapter 8) and speeding up test execution (chapter 9).
It is a pity to have to criticize the book´s title, but I consider it to be misleading, as is the title of chapter 6 (Trustworthiness), which I thought would delve into what constitute fragile tests, but which limits itself to examining mismatchs between comments and code. The problem in the book´s title is the use of the word effective. While the refactorization techniques do improve the quality of the test code, I for one, would have liked to see the author tackle the key issue of unit testing strategies. At the very least, some hints on how to write tests to catch defects effectively would have been greatly appreciated.
In short, a nice, well-written effort, well- worth reading if you are relatively new to unit testing or have arrived at an intermediate level of Java mastery.
"Effective Unit Testing" felt familiar to me. I think it is because I read "Test Driven" and saw the author present some of the content from this title at the 2012 Server Side Java Symposium. You can get a feel for some of the smells from my live blog post of that session http://www.selikoff.net/2011/03/16/te...
Part one sets the stage. It walks you through a hypothetical teams journey - no tests → tests → test driven! I liked the examples of bad code and bad test examples. And I really like the explanation of different types of test doubles. I also liked the example of jMock vs Mockito to do the same thing.
Part two shows you a series of test smells and how to fix them. One of my favorites is something really simple. How to make a bowling example more readable by using method names so you can embed "magic values" in the code. I also particularly liked the segment on how parameterized tests can be an anti-pattern along with how to avoid this problem.
Part three is "other things." It covers using other JVM languages to test and how to make your tests faster. Both via the tests and running them in the cloud. I really liked the part on how to profile in both Ant (which I knew) and Maven (which I haven't needed to yet.)
While there is an appendix to get you up to speed on JUnit, you should read a different book if you are trying to get up to speed on JUnit. I recommend "JUnit in Action" or "Test Driven" for that. Once you know any unit testing framework, it is time to come back to this book so you can write better tests.
It was a great book. My only problem was that having seen the session some was repetitive. But I highly recommend both the book and the talk.
--- Disclosure: I received a copy of this book from the publisher in exchange for writing this review on behalf of CodeRanch.
Muy bueno en lineas generales, buena clasificación de test y muy desarrollado cada uno, usos eficientes y problemas habituales... Habla de groovy para explayar un poco y no ser puro java pero por hablar, se queda corto en las ventajas del lenguaje... Los anexos son en su mayoría de cosas ya explicadas, solo agregan el concepto de runner junit que me parecio muy bueno... Muy bueno el capitulo de mejorar la velocidad de los test y de junit parametrizado
Not a bad book but didn't match my expectations: I was expecting a more advanced or deeper book but the book provided hardly anything new. Probably good for beginners.
Didn't like to conversational writing style, could have been condensed a lot. But that might also be a good way to keep the book more approachable for beginners.
Lasse covers since the basics (why unit testing is important) to what characteristics those tests should have. The book is well structured in a manner that is easy to read and follow without requiring to pause to investigate material not in the book.
The structure followed is: what we are trying to achieve; bad examples; how to fix those bad conditions in the pursuit of better outcome. He explains why each characteristic is important and depict advantages and disadvantages of the approaches taken (when and when not to use)
I strongly recommend this book for people that do not have profound knowledge on Unit Testing best practices, the importance of test driven design (and development) and how crucial reproducibility, readability and maintainability are for the future of the software.
The book starts really boring. Part 1 could definitely be improved. At times, it looked to me that the book lacked cohesion, but after finishing the book down it surely feels better. The examples were well put, and the book is a good read for beginners and those looking to impove their Unit testing game.
I picked this book as someone new to Java to learn about writing unit tests for that specific language. In that sense, I was disappointed and will likely pick up another book to help me understand how unit testing applies to Java and the tools available for this work (such as jUnit and Hamcrest). The book does offer an approachable look at what makes a (subjectively) good unit test, and I would recommend this book before reading something more academic like Xunit Test Patterns: Refactoring Test Code, because the author does a good job at making the subject matter approachable.
Effective Unit Testing is a must read for new developers and testers. The author dives deep into what makes a good test and in doing so also shows how these tests can lead to better code design.
This might not be new information for experienced developers that are comfortable with unit testing. However if you are unable or unwilling to write good unit tests this book is simple to read and very valuable.
The methods discussed in this book can also be extended for integration testing as well so I'd recommend this to high-level testers too.
This book was extremely informative and very engaging, a rare combo.
I think I'll finally be able to use these philosophies and methodologies in my own work now. Just because I read a book doesn't mean I'm "test-infected," but maybe I will be soon--here goes.
Very nice book with tons of useful content. The problem is that it's neither for beginners nor for very advanced developers. In other words, read it and read it well, but don't set your expectations too high. You'll learn from it, but then there will still be more.
The book describes decent, practical set of test smells and solutions I personally have both encourtered and produced myself over the years. Some more advanced and complex cases would've been nice.
This book assumes previous Unit testing experience. Beneficial to people who have written lot of test cases and looking to improve their skills. (Java Based)