This is perhaps the most difficult section to write because of the number of people who participated directly or indirectly in this book.
I will start by thanking my father, mother, and brother, who supported me all the time on the decision to get a master's degree, understanding how science should be done, and who suffered with me in the times of great stress (which happens during all master's!).
I also thank my master's and doctorate advisor, Professor Dr. Marco Aurelio Gerosa, who taught me how things work over there. Without him, I think this book would be very different; it would be more passionate, but less true. If my text focuses on TDD in an unbiased and impartial way, he is the one to blame.
Paulo Silveira and Adriano Almeida also deserve a reminder. Even when "Casa do Código" did not in fact exist, they had already accepted the idea of the book on TDD. Thanks for the confidence.
All people from the previous companies at which I worked also helped me with the countless hallway conversations about the subject. This certainly greatly enriched the text.
Thanks also to friends José Donizetti, Guilherme Moreira, and Rafael Ferreira, who spent time reading the book and giving me suggestions on how to improve.
Finally, thanks to you, the reader of this book. I hope it helps.
My name is Maurício Aniche, and I have worked in software development for about 11 years. In most of these 11 years, I worked as a consultant for different companies in the Brazilian and international markets. Surely, the languages I used most throughout my career were Java, C#, and C.
As I always jumped from project to project (and, therefore, from technology to technology), I never went too deeply into any of them. On the contrary, I always focused on understanding principles that could be taken from one technology to another, so that in the end the code would have quality, independently from the technology used.
In my final year of school before graduation, in 2007, I started reading more about the idea of automated testing and Test-driven Development (TDD). I found the idea very interesting, and I believed it to be useful to write a program to test your program, and I decided to practice TDD on my own to better understand how it worked.
I really liked what I found. From 2007 onwards, I decided to practice, research, and better disseminate my ideas on the subject. I started slowly, just blogging what was on my mind, sharing that I would appreciate some feedback from other developers. But in order to make a more decent approach, I decided to enter the master's program at the University of São Paulo. There, I researched the effects of practicing TDD in design classes.
At that time, I attended most of the events related to the subject. I lectured in the main events of agile methods in the country (Agile Brazil, Agile Meeting), software development (QCON SP and DNAD), among other smaller ones. I also participated in international events; I was the only Brazilian speaker in the First International Workshop on TDD in 2010, in the city of Paris. I have also participated in academic events. In 2011, I presented a study on TDD at the WBMA (Brazilian Workshop on Agile Methods) and, in 2012, at the largest Brazilian symposium on software engineering, the SBES.
Currently, I work for Caelum as a consultant and trainer. I am also a PhD student at the University of São Paulo, where I continue research about the relation of unit testing and code quality.
Therefore, this is my relationship with TDD. In recent years, I have looked at it from all possible points of view: practitioner, academic, researcher, passionate, cold. This book is an account of everything I have learned in these years.
TDD is one of the practices of software development suggested by various agile methodologies, such as XP. The idea is to make the developer write automated tests steadily throughout the development. However, unlike what we are used to, TDD suggests that the TDD developer should write the test even before implementation.
This simple cycle inversion brings many benefits to the project. Test batteries tend to be larger, covering more cases and ensuring a higher external quality. Moreover, writing unit tests will force the developer to write code of higher quality because, as we will notice throughout the book, in order to write good unit tests, the developer is obliged to make good use of object orientation.
Practice helps us write better software with better quality, and a better code is more easily maintained and evolved. These two points are very important in any software, and TDD helps us to reach them. Every practice that helps to increase the quality of the software produced should be studied.
In this book, I tried to include the whole experience and everything I have learned over these past years practicing and researching on the subject. I also showed the other side of the practice, its effects on the design of classes, which is widely spoken about but rarely discussed and explained. The practice of TDD, when correctly used, can be quite productive. However, as you will see throughout the book, practitioners should always be alert to the clues that the test will provide about our code. Here, we will go through them, and at the end of the book, the reader will have at hand a great new development tool.
This book is intended for developers who want to learn to write tests efficiently and who want to learn how to further improve the code they produce. In this book, we use Java to demonstrate the concepts discussed, but you can easily transfer the discussions made here to your favorite programming language. Even if you already practice TDD, I am sure that here you will find interesting discussions on how the practice provides feedback about problems of coupling and cohesion, as well as techniques for writing better tests that are easier to maintain.
Testers can also benefit from this book, understanding how to write test code with quality, whether using TDD or not, and how to report code problems for the developers.
Throughout this book, we work on several examples, very similar to the real world. Every chapter has a practical part and a theoretical part. In the practical part, much test code is written. In the theoretical part, we reflect on the code produced up to that time, what was done well, what was badly done, and we improve it accordingly.
The reader can remake all codes produced in the chapters. Practicing TDD is essential for the ideas to become natural. Furthermore, Caelum also provides an online course of automated testing *, which can be used as a supplement for this book.
Enjoy your reading!