Java Unit Testing with JUnit 5 -  Shekhar Gulati,  Rahul Sharma

Java Unit Testing with JUnit 5 (eBook)

Test Driven Development with JUnit 5
eBook Download: PDF
2017 | 1. Auflage
XIII, 158 Seiten
Apress (Verlag)
978-1-4842-3015-2 (ISBN)
Systemvoraussetzungen
79,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen
Explore the new way of building and maintaining test cases with Java test driven development (TDD) using JUnit 5. This book doesn't just talk about the new concepts, it shows you ways of applying them in TDD and Java 8 to continuously deliver code that excels in all metrics. 

Unit testing and test driven development have now become part of every developer's skill set. For Java developers, the most popular testing tool has been JUnit, and JUnit 5 is built using the latest features of Java.  With Java Unit Testing with JUnit 5, you'll master these new features, including method parameters, extensions, assertions and assumptions, and dynamic tests. You'll also see how to write clean tests with less code. 

This book is a departure from using older practices and presents new ways of performing tests, building assertions, and injecting dependencies. 

What You Will Learn
  • Write tests the JUnit 5 way 
  • Run your tests from within your IDE
  • Integrate tests with your build and static analysis tools
  • Migrate from JUnit 4 to JUnit 5

Who This Book Is For

Java developers both with and without any prior unit testing experience.



Shekhar Gulati is a seasoned Java programmer with more than 11 years of Java software development experience. He is also a public speaker and technology blogger. He is the author of the OpenShift Cookbook, published in October 2014.

Rahul Sharma is a seasoned Java developer with over 11 years of industry experience. He is an open-source enthusiast and has worked on various projects such as Apache Crunch and HDT. He is the author of NGINX High Performance, published in July 2015.

Explore the new way of building and maintaining test cases with Java test driven development (TDD) using JUnit 5. This book doesn't just talk about the new concepts, it shows you ways of applying them in TDD and Java 8 to continuously deliver code that excels in all metrics. Unit testing and test driven development have now become part of every developer's skill set. For Java developers, the most popular testing tool has been JUnit, and JUnit 5 is built using the latest features of Java. With Java Unit Testing with JUnit 5, you'll master these new features, including method parameters, extensions, assertions and assumptions, and dynamic tests. You'll also see how to write clean tests with less code. This book is a departure from using older practices and presents new ways of performing tests, building assertions, and injecting dependencies. What You Will LearnWrite tests the JUnit 5 way Run your tests from within your IDEIntegrate tests with your build and static analysis toolsMigrate from JUnit 4 to JUnit 5Who This Book Is ForJava developers both with and without any prior unit testing experience.

Shekhar Gulati is a seasoned Java programmer with more than 11 years of Java software development experience. He is also a public speaker and technology blogger. He is the author of the OpenShift Cookbook, published in October 2014.Rahul Sharma is a seasoned Java developer with over 11 years of industry experience. He is an open-source enthusiast and has worked on various projects such as Apache Crunch and HDT. He is the author of NGINX High Performance, published in July 2015.

Contents at a Glance 4
Contents 5
About the Authors 10
About the Technical Reviewer 11
Chapter 1: Building Software the Correct Way 12
Test-Driven Development 13
Detect Regression Errors 14
Keep System Design Simple 14
Levels of Testing 15
Benefits of Unit Testing 16
Determines Specifications 17
Provides Early Error Detection 17
Supports Maintenance 17
Improves Design 17
Product Documentation 17
Characteristics of Good Unit Tests 18
JUnit Introduction 19
Why We Need a New Version of JUnit? 19
JUnit 5 20
Java 8 Primer 22
Lambdas 23
Streams API 23
Optional< T>
Project Setup 25
Writing Your First Test 29
Summary 34
Chapter 2: Understanding Core JUnit 5 35
Test Class 35
Constructors 37
Using @DisplayName 38
Test Method 39
Parameters in Test Methods 39
Using @DisplayName 40
Assertions 41
Grouping Assertions 44
Error vs. Failure 46
JUnit Life Cycle API 47
@BeforeAll 48
@BeforeEach 48
@AfterEach 49
@AfterAll 49
Test Execution 51
Summary 54
Chapter 3: Developing an Application with JUnit 5 55
Bookstoread Application 55
First Feature 55
Write a Failing Test 56
Make Test Pass 57
Refactor the Code 58
Add Test Cases for Exception Scenarios 59
Using @BeforeEach 61
Second Feature 61
Write a Failing Test Case 61
Make Test Pass 62
Refactor 63
Disabled Tests 67
AssertJ 69
Using @DisplayName 70
Third Feature 72
Write a Failing Test 72
Make Test Pass 73
Refactor 73
Nested Tests 74
Summary 76
Chapter 4: Dependency Injection, Mocking, Testing Traits, and Grouping Tests 77
Dependency Injection 77
Feature: Track Bookshelf Progress 82
Caching Test Data 86
Using ExtensionContext Store 87
Feature: Search BookShelf 88
Mocking 93
Testing Traits 96
Grouping Tests by Tags 97
Summary 98
Chapter 5: Testing Exceptions 99
Context Setting 99
Primitive Way: Using the try-catch-fail 99
JUnit 4 Way: @Test Annotation and Rule API 101
JUnit 5 Way: Using assertThrows Assertion Method 102
Using JUnit 4 ExpectedException Rule with JUnit 5 103
Exception Handling Extension 104
Working with Test Timeout 105
assertTimeoutPreemptively 106
Repeated Tests 106
Summary 108
Chapter 6: Integrating Tools 109
Build Tools 109
Gradle 109
Maven 114
Ant 118
Code Coverage 123
Gradle Extension 123
Maven Extension 125
Ant Extension 126
Other Tools 127
Summary 129
Chapter 7: JUnit 5 Extension Model 130
JUnit 4 Extension Model 130
JUnit 5 Extension Model 131
Test Life Cycle Callbacks 133
Test Instance Post-Processing 135
Conditional Test Execution 136
Parameter Resolution 136
Exception Handling 138
Registering Extensions 138
JUnit 5 Extensions 139
Test Template 139
Parameterized Test 142
Summary 146
Chapter 8: Dynamic Tests and Migration from JUnit 4 147
Dynamic Tests 147
JUnit 4 Support 149
Using Vintage Engine 151
Moving to JUnit 5 152
Summary 155
Index 156

Erscheint lt. Verlag 10.11.2017
Zusatzinfo XIII, 151 p. 47 illus., 45 illus. in color.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Java
Informatik Software Entwicklung Objektorientierung
Informatik Software Entwicklung Qualität / Testen
Schlagworte Java 8 • JUnit • junit5 • TDD • Test driven development • unittesting
ISBN-10 1-4842-3015-9 / 1484230159
ISBN-13 978-1-4842-3015-2 / 9781484230152
Haben Sie eine Frage zum Produkt?
Wie bewerten Sie den Artikel?
Bitte geben Sie Ihre Bewertung ein:
Bitte geben Sie Daten ein:
PDFPDF (Wasserzeichen)
Größe: 3,6 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Einführung, Ausbildung, Praxis

von Christian Ullenboom

eBook Download (2023)
Rheinwerk Computing (Verlag)
49,90