paint-brush
Discover the 7 Best Books to develop effective Java Unit Testsby@ssaurel
5,650 reads
5,650 reads

Discover the 7 Best Books to develop effective Java Unit Tests

by Sylvain SaurelMarch 26th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The importance of Unit Tests in the world of IT development is clearly well established. For developers who still have doubts about the subject, I believe that the selection of books I will present in this article will prove to be a turning point in their careers. Indeed, Unit Tests must be the best friends of the computer programmer and above all, the cornerstone of any self-respecting business IT project.

People Mentioned

Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Discover the 7 Best Books to develop effective Java Unit Tests
Sylvain Saurel HackerNoon profile picture

The importance of Unit Tests in the world of IT development is clearly well established. For developers who still have doubts about the subject, I believe that the selection of books I will present in this article will prove to be a turning point in their careers. Indeed, Unit Tests must be the best friends of the computer programmer and above all, the cornerstone of any self-respecting business IT project.

The Unit Tests will allow you to develop a secure code and to control as well as possible the technical debt that will soon arrive as the project progresses. In 10 years, when someone has to make your IT project evolve, they will thank you forever if you have created a relevant suite of Unit Tests that will allow them to evolve the code with confidence. In addition, if he has to refactor it, the Unit Tests will also be a huge advantage, saving tens of thousands of dollars depending on the size of the project.

Without further ado, I suggest you discover my list of the 7 Best Books to learn how to develop effective Unit Tests in Java.

Growing Object-Oriented Software, Guided by Tests

The book “Growing Object-Oriented Software, Guided by Tests” covers much more than the application of Unit Tests in Java. It is a reference in this field to understand the strong correlation between Unit Tests, Test Driven Development (TDD) and Object-Oriented Programming (OOP).

The famous Robert C. Martin, better known as “Uncle Bob”, who wrote the best-seller “Clean Code: A Handbook of Agile Software Craftsmanship” says the following about this book:

“At last, a book suffused with code that exposes the deep symbiosis between TDD and OOD. This one’s a keeper.”

If this is not enough to convince you of the importance of this book to the software industry, I could go on to quote Michael C. Feathers, author of the best-seller “Working Effectively with Legacy Code”, of this book:

“If you want to be an expert in the state of the art in TDD, you need to understand the ideas in this book.”

The book “Growing Object-Oriented Software, Guided by Tests” gives developers at any level the opportunity to become aware of the importance of TDD, which is now a well-established technique in the software industry for delivering better quality software faster. It shows how to implement it effectively from scratch while maintaining the motivation of developers throughout the life of a project.

Authors Steve Freeman and Nat Pryce then show how to create a cleaner, more expressive and indeed, more robust code. The creation of Unit Tests to ensure that the focus remains on the delivery of a quality code. Better still, the book will make all developers aware of how TDD, Mock Objects and Object-Oriented Programming can intertwine in real life when developing an IT project.

Starting from more or less complex concrete cases, the book “Growing Object-Oriented Software, Guided by Tests” will maximize the developers’ chances of success in the application of TDD. You will be able to apply TDD for the management of complex data, data persistence or on competing aspects of program code.

Book on Amazon :Growing Object-Oriented Software, Guided by Tests

Test Driven Development: By Example

Inventor of the concept of eXtreme Programming (XP) and author of a large number of reference books on the method, Kent Beck is a well known name in the world of computer development and more particularly software testing. He contributed to the popularization of Test Driven Development by making it an essential XP practice. With Erich Gamma, he created the JUnit framework that all Java developers have been using for many years on a daily basis.

His book “Test Driven Development: By Example” is the reference in this field for the implementation of TDD and must be read at least once by all developers who respect themselves! It will present two projects developed via the TDD from start to finish. This illustrates the techniques that computer programmers can use to increase the quality of their code.

The many examples in this book clearly highlight all the patterns of the TDD and how to refactor computer code effectively. Logically, the book is a reference for all enthusiasts of agile methods, whether XP or Scrum, and people who want to develop software quickly while maintaining an optimal level of quality.

Book on Amazon :Test Driven Development: By Example

xUnit Test Patterns: Refactoring Test Code

We continue with the reference books in the world of Unit Tests, whether in Java or any other programming language. As such, Gerard Meszaros’ book “xUnit Test Patterns: Refactoring Test Code” is also a must-read for all developers. This book will enable them to meet the challenge of creating efficient and effective automated tests. It is the ultimate guide for anyone who wants to write automated tests based on the xUnit family frameworks (JUnit, NUnit, …).

The book “xUnit Test Patterns: Refactoring Test Code” highlights 68 patterns that have proven to easily create tests that are understandable and maintainable over time. All this while keeping in mind that they must be repeatable but also cost-effective. It is something that is too often overlooked by other books and it is good that this book refers to it.

After reading this best-seller by Gerard Meszaros, your vision of automated testing will be changed forever and you will be able to write quality tests quickly. You will know at your fingertips the four phases of any automated test: setting up the test environment, testing the system, verifying test results and restoring the initial environment. You will know how to take advantage of Stubs Tests and Mock Objects to improve test coverage by isolating the software from its environment.

Finally, you will be able to design software that is easier to test while recognizing the famous “test smells” more quickly to protect yourself and develop better quality code. In short, it is a book that you must absolutely read!

Book on Amazon :xUnit Test Patterns: Refactoring Test Code

Effective Unit Testing: A guide for Java developers

The book “Effective Unit Testing: A guide for Java developers” will show you how to create effective Unit Tests by focusing specifically on the world of Java developers. After discovering the theory of Unit Tests and TDD, this book is the logical continuation. You will discover step by step how to create concise, useful, expressive and above all, maintainable tests. This is an essential issue and one that often comes up in the world of software testing. It is essential that your Unit Test suites are maintainable, otherwise they will likely end up dying in a corner…

Focusing on the tools and practices of the Java world, Lasse Koskela’s book “Effective Unit Testing: A guide for Java developers” even goes so far as to introduce related techniques such as Behavior-Driven Development (BDD) and the example specification method. All this while showing you how to introduce these practices into your Java developer toolbox. Finally, the third part of the book proposes an extension to the other languages of the JVM (Groovy, Scala,…) so that the developers of these languages can also discover how to put into practice the valuable tips of this book.

Book on Amazon :Effective Unit Testing: A guide for Java developers

Java Unit Testing with JUnit 5: Test Driven Development with JUnit 5

Published in 2017, version 5 of the Junit framework uses the new features introduced by Java 8 such as Lambdas or repeated annotations. All Java developers know JUnit, at least hopefully, but many have stayed with the previous version of JUnit 4, and the book “Java Unit Testing with JUnit 5: Test Driven Development with JUnit 5” aims to help developers discover the new features of JUnit 5 and even better, put them into practice. The goal is to show them how to write unit tests with JUnit 5 and how to migrate their unit test suites from JUnit 4 to JUnit 5.

Written by Shekhar Gulati and Rahul Sharma, the book “Java Unit Testing with JUnit 5: Test Driven Development with JUnit 5” not only presents the new features of JUnit 5, but also goes further by showing Java developers how to take advantage of JUnit 5 in the implementation of TDD on Java IT development projects. All with the objective of delivering high quality Java 8 (and higher) code that excels in all test metrics used in the software industry.

Book on Amazon :Java Unit Testing with JUnit 5: Test Driven Development with JUnit 5

Pragmatic Unit Testing in Java 8 with JUnit

Released in 2003, the book “Pragmatic Unit Testing In Java With JUnit” was a huge success. Since then, the Java language has changed enormously, the authors of the original book Andy Hunt and Dave Thomas have been joined by Jeff Langr in writing a highly anticipated sequel: “Pragmatic Unit Testing in Java 8 with JUnit”. The revisited version of this classic will teach you how to write Unit Tests that can be easily maintained using JUnit.

Even better, this book will teach you what tests to write and what are the essential qualities of a good test. You will discover how Unit Tests will allow you to keep the code of your computer system clean while addressing features that seem complex at first glance. The examples in the book cover Eclipse, IntelliJ IDEA and NetBeans, which are the three reference IDEs in the Java world.

The book “Pragmatic Unit Testing in Java 8 with JUnit” is also based on the feedback from the three authors. After reading this book, you will be able to design unit tests that minimize maintenance efforts and help you keep your computer system clean. You will no longer be afraid to tackle the test of the most difficult features. Finally, you will know what is important when writing your unit tests. All this should enable you to keep your development teams permanently engaged in writing quality Unit Tests.

Book on Amazon :Pragmatic Unit Testing in Java 8 with JUnit

Practical Unit Testing with TestNG and Mockito

Most Java developers use the JUnit reference framework to create automated Unit Tests on Java projects. However, JUnit is not the only quality solution available to them. Created by the French engineer Cédric Beust, TestNG is a test framework that should be known. Inspired by JUnit and NUnit, TestNG aims to cover a wider range of test categories. In addition to Unit Tests, it facilitates the creation of Integration Tests, System Tests or Acceptance Tests.

The book “Practical Unit Testing with TestNG and Mockito” explains how to implement a Unit Testing strategy on Java projects using TestNG and Mockito. The latter being one of the frameworks for creating Mock Objects reference in the Java world. Author Tomek Kaczanowski presents a wide range of techniques necessary for writing high quality Unit Tests. Thus, he reviews mocking techniques, parameterized tests and matches. It also provides an interesting insight into the choices to be made in concrete cases that you encounter at one time or another on IT projects.

As they read this book, Java developers will also learn how to set up the right Unit Tests by applying the TDD method and how to avoid a large number of errors common to projects conducted in TDD mode. The advantage of the book is that each theoretical part is accompanied by code examples. Finally, Java developers will welcome the discovery of the Mockito framework, which they can also use on projects that have chosen JUnit as their Unit Testing framework.

Book on Amazon :Practical Unit Testing with TestNG and Mockito

Conclusion

Unit Tests are essential in all IT projects and must become the best friend of any developer who wants to pursue a career in the software industry. This selection will also have allowed you to understand that Unit Tests are strongly linked to the practice of development driven by tests that are strongly recommended to apply to produce quality software that can be maintained over time.

Feel free to react in comments by sharing the books you find most appropriate to learn how to develop effective Java Unit Tests.

If you want to discover some books to learn Java programming, I advice you to read the following article with my selection of the Top 6 Best Books for Java programming :

Top 6 Best Books for learning Java Programming