eBook - ePub
Unit Testing Principles, Practices, and Patterns
Vladimir Khorikov
This is a test
Partager le livre
- English
- ePUB (adapté aux mobiles)
- Disponible sur iOS et Android
eBook - ePub
Unit Testing Principles, Practices, and Patterns
Vladimir Khorikov
DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations
Ă propos de ce livre
Unit Testing Principles, Patterns and Practices shows you how to refine your existing unit tests by implementing modern best practices. You'll learn to spot which tests are performing, which need refactoring, and which need to be deleted entirely! Upgrade your testing suite with new testing styles, good patterns, and reliable automated testing.
Foire aux questions
Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier lâabonnement ». Câest aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via lâapplication. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă la bibliothĂšque et Ă toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode dâabonnement : avec lâabonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă 12 mois dâabonnement mensuel.
Quâest-ce que Perlego ?
Nous sommes un service dâabonnement Ă des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă toute une bibliothĂšque pour un prix infĂ©rieur Ă celui dâun seul livre par mois. Avec plus dâun million de livres sur plus de 1 000 sujets, nous avons ce quâil vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Ăcouter sur votre prochain livre pour voir si vous pouvez lâĂ©couter. Lâoutil Ăcouter lit le texte Ă haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, lâaccĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Unit Testing Principles, Practices, and Patterns est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă Unit Testing Principles, Practices, and Patterns par Vladimir Khorikov en format PDF et/ou ePUB ainsi quâĂ dâautres livres populaires dans Informatica et Controllo qualitĂ e test. Nous disposons de plus dâun million dâouvrages Ă dĂ©couvrir dans notre catalogue.
Informations
Sujet
InformaticaSous-sujet
Controllo qualitĂ e testPart 1. The bigger picture
This part of the book will get you up to speed with the current state of unit testing. In chapter 1, Iâll define the goal of unit testing and give an overview of how to differentiate a good test from a bad one. Weâll talk about coverage metrics and discuss properties of a good unit test in general.
In chapter 2, weâll look at the definition of unit test. A seemingly minor disagreement over this definition has led to the formation of two schools of unit testing, which weâll also dive into. Chapter 3 provides a refresher on some basic topics, such as structuring of unit tests, reusing test fixtures, and test parametrization.
Chapter 1. The goal of unit testing
This chapter covers
- The state of unit testing
- The goal of unit testing
- Consequences of having a bad test suite
- Using coverage metrics to measure test suite quality
- Attributes of a successful test suite
Learning unit testing doesnât stop at mastering the technical bits of it, such as your favorite test framework, mocking library, and so on. Thereâs much more to unit testing than the act of writing tests. You always have to strive to achieve the best return on the time you invest in unit testing, minimizing the effort you put into tests and maximizing the benefits they provide. Achieving both things isnât an easy task.
Itâs fascinating to watch projects that have achieved this balance: they grow effortlessly, donât require much maintenance, and can quickly adapt to their customersâ ever-changing needs. Itâs equally frustrating to see projects that failed to do so. Despite all the effort and an impressive number of unit tests, such projects drag on slowly, with lots of bugs and upkeep costs.
Thatâs the difference between various unit testing techniques. Some yield great outcomes and help maintain software quality. Others donât: they result in tests that donât contribute much, break often, and require a lot of maintenance in general.
What you learn in this book will help you differentiate between good and bad unit testing techniques. Youâll learn how to do a cost-benefit analysis of your tests and apply proper testing techniques in your particular situation. Youâll also learn how to avoid common anti-patternsâpatterns that may make sense at first but lead to trouble down the road.
But letâs start with the basics. This chapter gives a quick overview of the state of unit testing in the software industry, describes the goal behind writing and maintaining tests, and provides you with the idea of what makes a test suite successful.
1.1. The current state of unit testing
For the past two decades, thereâs been a push toward adopting unit testing. The push has been so successful that unit testing is now considered mandatory in most companies. Most programmers practice unit testing and understand its importance. Thereâs no longer any dispute as to whether you should do it. Unless youâre working on a throwaway project, the answer is, yes, you do.
When it comes to enterprise application development, almost every project includes at least some unit tests. A significant percentage of such projects go far beyond that: they achieve good code coverage with lots and lots of unit and integration tests. The ratio between the production code and the test code could be anywhere between 1:1 and 1:3 (for each line of production code, there are one to three lines of test code). Sometimes, this ratio goes much higher than that, to a whopping 1:10.
But as with all new technologies, unit testing continues to evolve. The discussion has shifted from âShould we write unit tests?â to âWhat does it mean to write good unit tests?â This is where the main confusion still lies.
You can see the results of this confusion in software projects. Many projects have automated tests; they may even have a lot of them. But the existence of those tests often doesnât provide the results the developers hope for. It can still take programmers a lot of effort to make progress in such projects. New features take forever to implement, new bugs constantly appear in the already implemented and accepted functionality, and the unit tests that are supposed to help donât seem to mitigate this situation at all. They can even make it worse.
Itâs a horrible situation for anyone to be inâand itâs the result of having unit tests that donât do their job properly. The difference between good and bad tests is not merely a matter of taste or personal preference, itâs a matter of succeeding or failing at this critical project youâre working on.
Itâs hard to overestimate the importance of the discussion of what makes a good unit test. Still, this discussion isnât occurring much in the software development industry today. Youâll find a few articles and conference talks online, but Iâve yet to see any comprehensive material on this topic.
The situation in books isnât any better; most of them focus on the basics of unit testing but donât go much beyond that. Donât get me wrong. Thereâs a lot of value in such books, especially when you are just starting out with unit testing. However, the learning doesnât end with the basics. Thereâs a next level: not just writing tests, but doing unit testing in a way that provides you with the best return on your efforts. When you reach this point, most books pretty much leave you to your own devices to figure out how to get to that next level.
This book takes you there. It teaches a precise, scientific definition of the ideal unit test. Youâll see how this definition can be applied to practical, real-world examples. My hope is that this book will help you understand why your particular project may have gone sideways despite having a good number of tests, and how to correct its course for the better.
Youâll get the most value out of this book if you work in enterprise application development, but the core ideas are applicable to any software project.
What is an enterprise application?
An enterprise application is an application that aims at automating or assisting an organizationâs inner processes. It can take many forms, but usually the characteristics of an enterprise software are
- High business logic complexity
- Long project lifespan
- Moderate amounts of data
- Low or moderate performance requirements
1.2. The goal of unit testing
Before taking a deep dive into the topic of unit testing, letâs step back and consider the goal that unit testing helps you to achieve. Itâs often said that unit testing practices lead to a better design. And itâs true: the necessity to write unit tests for a code base normally leads to a better design. But thatâs not the main goal of unit testing; itâs merely a pleasant side effect.
The relationship between unit testing and code design
The ability to unit test a piece of code is a nice litmus test, but it only works in one direction. Itâs a good negative indicatorâit points out poor-quality code with relatively high accuracy. If you find that code is hard to unit test, itâs a strong sign that the code needs improvement. The poor quality usually manifests itself in tight coupling, which means different pieces of production code are not decoupled from each other enough, and itâs hard to test them separately.
Unfortunately, the ability to unit test a piece of code is a bad positive indicator. The fact that you can easily unit test your code base doesnât necessarily mean itâs of good quality. The project can be a disaster even when it exhibits a high degree of decoupling.
What is the goal of unit testing, then? The goal is to enable sustainable growth of the software project. The term sustainable is key. Itâs quite easy to grow a project, especially when you start from scratch. Itâs much harder to sustain this growth over time.
Figure 1.1 shows the growth dynamic of a typical project without tests. You start off quickly because thereâs nothing dragging you down. No bad architectural decisions have been made yet, and there isnât any existing code to worry about. As time goes by, however, you have to put in more and more hours to make the same amount of progress you showed at the beginning. Eventually, the development speed slows down significantly, sometimes even to the point where you canât make any progress whatsoever.