Effective Unit Testing

by Piotr Likus on January 6, 2015
Item Reviewed

Effective Unit Testing. A guide for Java developers.

January 6, 2015
Book author(s)

Lasse Koskela


Manning Publications Co.





Publication year



I started writing my unit tests at university – long time ago using C++. At that time I felt in some cases this kind of tests is required for at last part of my code. Now I use it everywhere I can (sometimes it’s impossible due to software architecture), so I decided to buy “Effective Unit Testing” in order to organize my knowledge about this type of testing.

“Effective Unit Testing” is a short & practical introduction to unit testing basing on Java & JUnit code examples. The book can be useful for users of other unit test tools too as it describes universal topics like code maintainability and readability or built time improvement.

The book starts with solid, generic introduction to unit testing – it’s concepts & design rules and it can be useful also for non-Java programmers. Code examples presented inside the book are using JUnit as a test framework (in appendix you can find a short introduction for this tool). Next author presents in details each type of test double. Author shows also how to use Groovy to prepare shorter versions of unit tests.

If you are looking for BDD introduction, you can find one chapter in this book related to the topic. Describes Groovy “easyb” and “Spock Framework” as tools for this job.

At the end you can find a whole chapter presenting tools & tricks that can be used to optimize build & test processing performance (including Amazon’s AWS and GridGain).

What I missed in this book was two things:

  • mocking – was rather shortly described (5 pages)
  • database testing – was not described at all (in 9.2.6 author just mentions you should not test database if not required), see “Well-Grounded Java Developer” for this

Whole book is well organized illustrated with diagrams and with short sample codes (so it’s more interesting). I really liked summary parts after each chapter so I could repeat knowledge just acquired. Also when you register the paper book you receive an e-book for free from the publisher – Manning Publications Co.


The book contains several important parts:

  • “The promise of good tests”: how unit testing influence coding, why it’s important
  • “In search for good”: how to write solid tests, why test code readability is something you need
  • “Test doubles”: describes kinds of test doubles: test stub, fake object, test spy, mock object
  • “Readability”: whole chapter describing how to write easy to read code (test code)
  • “Maintainability”: what kinds of problems can appear from using inappropriate code constructions in test code
  • “Trustworthiness”: when tests start to be misleading and you feel “secure” about code that has in fact bugs
  • “Testable design”: how you can write your software in a way it can be tested
  • “Writing tests in other JVM languages”: what are benefits of using Groovy or BDD tools with Java code
  • “Speeding up test execution”: how to investigate if and where tests are slow (profiling), what types of solutions are there for speeding up tests (parallel & distributed runs)
  • “Appendix A: JUnit primer”: how to construct tests for JUnit, including Hamcrest matchers (custom validators)
  • “Appendix B: Extending JUnit”: using “@Rule” in order to extend JUnit functionality


Would I recommend it? Sure. I would like to see inside more about mocking, but the path author took – presenting testing concepts around JUnit was for me a best choice – practical & not too long.


* code examples easy to understand


* not too much about mocking (JMock etc.)
* virtually nothing about database (DAO) object testing

Our Rating
User Rating
Rate Here
Bottom Line

Easy to understand generic introduction to unit testing with Java/JUnit code examples.

Total Score
User Score
You have rated this
Fonts by Google Fonts. Icons by Fontello. Full Credits here »