Mastering Software Testing with Junit 5: Comprehensive Guide to Develop
Total Page:16
File Type:pdf, Size:1020Kb
Mastering Software Testing with JUnit 5 Comprehensive guide to develop high quality Java applications Boni García BIRMINGHAM - MUMBAI Mastering Software Testing with JUnit 5 Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: October 2017 Production reference: 1231017 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78728-573-6 www.packtpub.com Credits Author Copy Editor Boni García Charlotte Carneiro Reviewers Project Coordinator Luis Fernández Muñoz Ritika Manoj Ashok Kumar S Commissioning Editor Proofreader Smeet Thakkar Safis Editing Acquisition Editor Indexer Nigel Fernandes Aishwarya Gangawane Content Development Editor Graphics Mohammed Yusuf Imaratwale Jason Monteiro Technical Editor Production Coordinator Ralph Rosario Shraddha Falebhai About the Author Boni García has a PhD degree on information and communications technology from Technical University of Madrid (UPM) in Spain since 2011. His doctoral dissertation was focused on test automation for web applications. He is an author of more than 30 research papers, including international conferences, journals, and magazines. At the time of writing this book, he was working as a researcher at King Juan Carlos University (URJC), and also as assistant professor at Digital Art and Technology University (U-tad) in Spain. He has participated in different research initiatives. For instance, he is member of Kurento project, where he has created a testing framework for WebRTC applications. He also participates in the coordination of ElasTest, a project aimed to create an elastic platform for end-to-end testing of different types of applications. Boni is an active member on the free open source software community with a big emphasis on software testing and web engineering. Among others, he is the owner and main developer of the WebDriverManager and selenium- jupiter projects (JUnit 5 extension for Selenium). First of all, I would like to thank my girl, Verónica, for her essential support while writing this book. Without you, this manuscript would have been simply impossible. But, most importantly, thank you for sharing your life with me. I would also like to thank to my sisters, Yoly and Inma, for all their help, not only with this book, but in life in general. Thank you for being always there. In addition, I want to dedicate this book to my nieces, Andrea, Silvia, and Laura, who are the most amazing people in the universe (at least the part I know). I also would like to remember here my parents, Pablo and Dolores. There is nothing I would like more than if you were here. I know that a part of you is living with us, in your daughters, grandchildren, and myself. I miss you so much. Finally, I also want to dedicate this book to the most important person in the world, my little boy, Pablo. Son, whenever you read this, I want you to know that I learned what happiness really means by looking into your eyes. I would like to believe these words can travel in time and space to give you a big hug anytime. Remember that your parents love you more than anything. About the Reviewers Luis Fernández Muñoz in the last 25 years he has been serving as a Professor and Researcher at Technical University of Madrid (UPM) and King Juan Carlos University (URJC), both in Spain. he has also collaborate as Consultor and Trainer in different public and private national and international institutions. His main expertise comprises all the software engineering disciplines, from coding and testing, to analysis, design, architecture, and project management, usually around C++/Java and Web/JEE technologies. As a Consultor in private companies, he has participated in different projects as different roles, from management to development of code and tests. In the different areas he has worked, he highlight cloud computing, combat simulation and physical activity expert systems, among others. Additional, my entrepreneur spirit took me to become in the one of co- founders of TS Company, an UPM startup with 25 employees in only four years. He has developed my research endeavor in the Natural Computing Group, in which he made his PhD dissertation focused on Parallel Algorithms for the Application of Evolution Rules in Endomembrane P Systems. After that, he has directed some others PhD dissertations. Thanks to all of this, he has participated in more than 60 publications, in conferences, journals, and several research projects. This versatile career has given me the opportunity of learn by reading and listening to relevant people in the field, which is one of his main hobbies. Deep reflections, discussions and building the mental structure of conceptual ideas rigorously, but his way, is his motivation challenge. Traveling, chatting, and venturing -without losing his mind- is the way he enjoy’s the best in life. Ashok Kumar S is an Android developer residing in Bangalore, India. A gadget enthusiast, he thrives on innovating and exploring the latest gizmos in the tech space. He has been developing softwares for all Google related technologies, and he also a Google certified Android developer. A strong believer in spirituality, he heavily contributes to the open source community as an e-spiritual ritual to improve his e-karma. He regularly conducts workshops about Android application development in local engineering colleges and schools. He also organizes multiple tech events at his organization and he is a regular attendee of all the conferences that happen on Android and Java related technologies in the silicon valley of India (Bengaluru). He also runs a YouTube channel, called AndroidABCD, where he discusses all aspects of Android development, including quick tutorials. Having 4 years of professional experience. Currently working with Dunst Technologies Pvt Ltd as full-time Sr. Mobile Engineer. He has extensively worked on Android Native applications ranging from Enterprise applications to commerce application. I spend most of my time in exploring brilliant architectures and libraries. I have a strong interest in code quality, testing, and automation, and all three. he is a speaker at Android conferences that happen’s in Bengaluru, Apart from all of it, I am also a photographer, A storyteller. www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub. com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.Pa cktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. https://www.packtpub.com/mapt Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book’s Amazon page at https://www.amazon.com/dp/1787285731. If you’d like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Errata Piracy Questions 1. Retrospective On Software Quality And Java Testing Software quality Quality engineering Requirements and specification Quality Assurance ISO/IEC-25000 Verification and Validation Software defects Static analysis Software testing Testing levels Unit testing Integration testing System testing Testing methods Black-box testing White-box testing Non-functional testing Testing types Other testing approaches Testing frameworks for the JVM JUnit 3 Standard tests in JUnit 3 Test execution in JUnit 3 JUnit 4 Standard tests in JUnit 4 Test execution in JUnit 4 Advanced features of JUnit 4 JUnit ecosystem Summary 2. What’s New In JUnit 5 Road to JUnit 5 JUnit 5 motivation Modularity JUnit 4 runners JUnit 4 rules JUnit 5 inception JUnit 5 community JUnit 5 architecture Test Engine SPI Test Launcher API Running tests in JUnit 5 Jupiter tests with Maven Jupiter tests with Gradle Legacy tests with Maven Legacy tests wih Gradle The ConsoleLauncher Jupiter tests in JUnit 4 IntelliJ Eclipse The extension model of JUnit 5 Test lifecycle Conditional extension points Dependency injection Third-party extensions Summary 3.