Suche
Lesesoftware
Info / Kontakt
Java Unit Testing with JUnit 5 - Test Driven Development with JUnit 5
von: Shekhar Gulati, Rahul Sharma
Apress, 2017
ISBN: 9781484230152 , 158 Seiten
Format: PDF, Online Lesen
Kopierschutz: Wasserzeichen
Preis: 66,99 EUR
eBook anfordern
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
25
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