E-Book, Englisch, 158 Seiten
Gulati / Sharma Java Unit Testing with JUnit 5
1. ed
ISBN: 978-1-4842-3015-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
Test Driven Development with JUnit 5
E-Book, Englisch, 158 Seiten
ISBN: 978-1-4842-3015-2
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
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 IDE
Integrate tests with your build and static analysis toolsMigrate 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.
Autoren/Hrsg.
Weitere Infos & Material
1;Contents at a Glance;4
2;Contents;5
3;About the Authors;10
4;About the Technical Reviewer;11
5;Chapter 1: Building Software the Correct Way;12
5.1;Test-Driven Development;13
5.1.1;Detect Regression Errors;14
5.1.2;Keep System Design Simple;14
5.2;Levels of Testing;15
5.3;Benefits of Unit Testing;16
5.3.1;Determines Specifications;17
5.3.2;Provides Early Error Detection;17
5.3.3;Supports Maintenance;17
5.3.4;Improves Design;17
5.3.5;Product Documentation;17
5.4;Characteristics of Good Unit Tests;18
5.5;JUnit Introduction;19
5.5.1;Why We Need a New Version of JUnit?;19
5.5.2;JUnit 5;20
5.6;Java 8 Primer;22
5.6.1;Lambdas;23
5.6.2;Streams API;23
5.6.3;Optional;25
5.7;Project Setup;25
5.8;Writing Your First Test;29
5.9;Summary;34
6;Chapter 2: Understanding Core JUnit 5;35
6.1;Test Class;35
6.1.1;Constructors;37
6.1.2;Using @DisplayName;38
6.2;Test Method;39
6.2.1;Parameters in Test Methods;39
6.2.2;Using @DisplayName;40
6.3;Assertions;41
6.3.1;Grouping Assertions;44
6.3.2;Error vs. Failure;46
6.4;JUnit Life Cycle API;47
6.4.1;@BeforeAll;48
6.4.2;@BeforeEach;48
6.4.3;@AfterEach;49
6.4.4;@AfterAll;49
6.5;Test Execution;51
6.6;Summary;54
7;Chapter 3: Developing an Application with JUnit 5;55
7.1;Bookstoread Application;55
7.1.1;First Feature;55
7.1.1.1;Write a Failing Test;56
7.1.1.2;Make Test Pass;57
7.1.1.3;Refactor the Code;58
7.1.1.4;Add Test Cases for Exception Scenarios;59
7.1.1.5;Using @BeforeEach;61
7.1.2;Second Feature;61
7.1.2.1;Write a Failing Test Case;61
7.1.2.2;Make Test Pass;62
7.1.2.3;Refactor;63
7.1.3;Disabled Tests;67
7.1.4;AssertJ;69
7.1.5;Using @DisplayName;70
7.1.6;Third Feature;72
7.1.6.1;Write a Failing Test;72
7.1.6.2;Make Test Pass;73
7.1.6.3;Refactor;73
7.1.7;Nested Tests;74
7.2;Summary;76
8;Chapter 4: Dependency Injection, Mocking, Testing Traits, and Grouping Tests;77
8.1;Dependency Injection;77
8.2;Feature: Track Bookshelf Progress;82
8.2.1;Caching Test Data;86
8.2.2;Using ExtensionContext Store;87
8.3;Feature: Search BookShelf;88
8.3.1;Mocking;93
8.3.2;Testing Traits;96
8.3.3;Grouping Tests by Tags;97
8.4;Summary;98
9;Chapter 5: Testing Exceptions;99
9.1;Context Setting;99
9.2;Primitive Way: Using the try-catch-fail;99
9.3;JUnit 4 Way: @Test Annotation and Rule API;101
9.4;JUnit 5 Way: Using assertThrows Assertion Method;102
9.5;Using JUnit 4 ExpectedException Rule with JUnit 5;103
9.6;Exception Handling Extension;104
9.7;Working with Test Timeout;105
9.7.1;assertTimeoutPreemptively;106
9.8;Repeated Tests;106
9.9;Summary;108
10;Chapter 6: Integrating Tools;109
10.1;Build Tools;109
10.1.1;Gradle;109
10.1.2;Maven;114
10.1.3;Ant;118
10.1.4;Code Coverage;123
10.1.4.1;Gradle Extension;123
10.1.4.2;Maven Extension;125
10.1.4.3;Ant Extension;126
10.2;Other Tools;127
10.3;Summary;129
11;Chapter 7: JUnit 5 Extension Model;130
11.1;JUnit 4 Extension Model;130
11.2;JUnit 5 Extension Model;131
11.3;Test Life Cycle Callbacks;133
11.4;Test Instance Post-Processing;135
11.5;Conditional Test Execution;136
11.6;Parameter Resolution;136
11.7;Exception Handling;138
11.8;Registering Extensions;138
11.9;JUnit 5 Extensions;139
11.9.1;Test Template;139
11.9.2;Parameterized Test;142
11.10;Summary;146
12;Chapter 8: Dynamic Tests and Migration from JUnit 4;147
12.1;Dynamic Tests;147
12.2;JUnit 4 Support;149
12.2.1;Using Vintage Engine;151
12.2.2;Moving to JUnit 5;152
12.3;Summary;155
13;Index;156




