Code is written by humans who make mistakes - hence bugs and the need for testing. Savvy Java developers know that not all testing is created equal. In addition to traditional functional testing, many shops are adopting developer testing techniques such as unit testing. Specific, automated tests are created to verify the accuracy and function of code while or even before it's written - to catch bugs early.
Unit Testing in Java teaches how to write good tests that are concise and to the point, useful, and maintainable. This book focuses on tools and practices specific to Java. It introduces emerging techniques like specification by example and behavior-driven development, and shows how to add robust practices into developers' toolkits.
Table of Contents
I. FOUNDATIONS 1. The promise of good tests 2. In search of good 3. Test doubles
II. CATALOG 4. Readability 5. Maintainability 6. Trustworthiness
III. DIVERSIONS 7. Testable design 8. Writing tests in other JVM languages 9. Speeding up test executions
Appendix A: JUnit primer Appendix B: Extending JUnit Index
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)