Practical Unit Testing with JUnit and Mockito (Anglais) Broché – 23 avril 2013
|Neuf à partir de||Occasion à partir de|
- Choisissez parmi 17 000 points de collecte en France
- Les membres du programme Amazon Prime bénéficient de livraison gratuites illimitées
- Trouvez votre point de collecte et ajoutez-le à votre carnet d’adresses
- Sélectionnez cette adresse lors de votre commande
Les clients ayant acheté cet article ont également acheté
Description du produit
Présentation de l'éditeur
This book explains in detail how to implement unit tests using two very popular open source Java technologies: JUnit and Mockito. It presents a range of techniques necessary to write high quality unit tests - e.g. mocks, parametrized tests and matchers. It also discusses trade-offs related to the choices we have to make when dealing with some real-life code issues.
The book stresses the importance of writing readable and maintainable unit tests, and puts a lot of stress on code quality. It shows how to achieve testable code and to eliminate common mistakes by following the Test Driven Development approach. Every topic discussed in the book is illustrated with code examples, and each chapter is accompanied by some exercises.
By reading this book you will:
- Grasp the role and purpose of unit tests
- Write high-quality, readable and maintainable unit tests
- Learn how to use JUnit and Mockito (but also other useful tools)
- Avoid common pitfalls when writing unit tests
- Recognize bad unit tests, and fix them in no time
- Develop code following the Test Driven Development (TDD) approach
- Use mocks, stubs and test-spies intelligently
- Measure the quality of your tests using code coverage and mutation testing
- Learn how to improve your tests' code so it is an asset and not a burden
- Test collections, expected exceptions, time-dependent methods and much more
- Customize test reports so that they show you what you really need to know
- Master tools and techniques your team members have never even heard of (priceless!) :)
Nowadays every developer is expected to write unit tests. While simple in theory, in practice writing high-quality unit tests can turn out to be a real challenge. This book will help.
Biographie de l'auteur
Aucun appareil Kindle n'est requis. Téléchargez l'une des applis Kindle gratuites et commencez à lire les livres Kindle sur votre smartphone, tablette ou ordinateur.
Pour obtenir l'appli gratuite, saisissez votre numéro de téléphone mobile.
Détails sur le produit
Si vous vendez ce produit, souhaitez-vous suggérer des mises à jour par l'intermédiaire du support vendeur ?
Meilleurs commentaires des clients
Un problème s'est produit lors du filtrage des commentaires. Veuillez réessayer ultérieurement.
I also enjoyed learning the concepts it explains such as direct and indirect inputs and outputs or SUT/DOC. It also has a section about mutation testing that is very interesting.
It is easy to read for any java developer and I really recommend it.
Commentaires client les plus utiles sur Amazon.com
- The theory is good and easy to understand.
- Hardly any examples in the book. There are no detailed TDD examples as well.
- End of book exercises are way more difficult than the sparse examples in the book.
- No guide or solutions to the end of chapter exercises. So, you don't know if you are doing TDD "correctly".
- Author does not reply to (succinct, polite and non spammy) emails that request for help.
Verdict: Might be good for people who have learned some TDD at work and/or practiced TDD in a language other than Java and want to learn Junit and Mockito.
PS: I would give the book 5 stars and pay $100 more for it, if it had detailed step by step solutions for all the exercises.
However, I'm going to spend a bit more time on the problems, because they're more interesting to talk about, but not because the book is only problems.
1) It needs a bit more editing. Certain parts of the book are not formatted well, and it is pretty noticeable. Again, reader, keep in mind my 4 star rating, it's not *SO BAD* to make it unreadable, just in a few places you get surprised by such a noticeable and easily fixable formatting problem.
2) It needs more integrated examples. Many of the examples are kept simple, which makes them clear about that particular concept, but then you look at your existing code and realize that it's significantly more complicated than the example in this book, and it's not so easy to transfer the use cases. A chapter on doing exactly that, looking at more complicated code and figuring out how to test it would be extremely helpful.
3) I bought this book because I have a reasonably complicated project than I wanted to learn how to test before I moved onto deployment. I would think that most of the people buying this book would be in that situation... it is a rare person who would think about testing before the code is actually written, unless you're already used to thinking that way. This book spends a large amount of time talking about that concept (Test Driven Development, or TDD) - it is the entirety of Chapter 4. However, I suspect that most readers either 1. already know about TDD and are using it, and therefore don't need that much of an in depth discussion of it, or 2. are like me, and are looking to test existing software. In my opinion, this book spends too much energy trying to teach people to use TDD, and not enough effort helping people add tests to their existing code that wasn't designed with TDD, nor enough effort on how to refactor existing code to make it more testable.
4) This is related to #3. I wish this book had a section on, "okay, your test has failed, but you don't know why". How can you modify your test and use a debugger to figure out why the test failed and how can you fix it? For example, if you use a mockito mock, and you say "verify that this method was called once" and it was called twice, what could/should you do to figure out where it was called from?
If you're looking for a book that teaches the latest versions of JUnit, Mockito, and related packages (CatchException, PowerMock, etc.), this book is for you. If you're looking for a book that will help you debug existing code and write tests for existing code, this book is not as helpful.
(1) SUT / Collaborators
(2) State verification vs Interaction verification
(3) Test doubles - Dummy, vs Fake vs Mock vs Test Spy
(4) Various Approaches : Sub-class and override vs. Partial Mocking vs. PowerMockito
Highly Recommended !
Not only are the examples practical, Tomek addresses discusses real dilemmas that we face in application testing. Check out the "Points of Controversy", real good stuff in that chapter for the experienced as well as the inexperienced.