𝔖 Scriptorium
✦   LIBER   ✦

πŸ“

Effective Unit Testing: A guide for Java Developers

✍ Scribed by Lasse Koskela


Publisher
Manning Publications
Year
2013
Tongue
English
Leaves
249
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Summary

Effective Unit Testing is written to show how to write good testsβ€”tests that are concise and to the point, expressive, useful, and maintainable. Inspired by Roy Osherove's bestselling The Art of Unit Testing, this book focuses on tools and practices specific to the Java world. It introduces you to emerging techniques like behavior-driven development and specification by example, and shows you how to add robust practices into your toolkit.

About Testing

Test the components before you assemble them into a full application, and you'll get better software. For Java developers, there's now a decade of experience with well-crafted tests that anticipate problems, identify known and unknown dependencies in the code, and allow you to test components both in isolation and in the context of a full application.

About this Book

Effective Unit Testing teaches Java developers how to write unit tests that are concise, expressive, useful, and maintainable. Offering crisp explanations and easy-to-absorb examples, it introduces emerging techniques like behavior-driven development and specification by example.

Programmers who are already unit testing will learn the current state of the art. Those who are new to the game will learn practices that will serve them well for the rest of their career.

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.

About the Author

Lasse Koskela is a coach, trainer, consultant, and programmer. He hacks on open source projects, helps companies improve their productivity, and speaks frequently at conferences around the world. Lasse is the author of Test Driven, also published by Manning.

What's Inside
  • A thorough introduction to unit testing
  • Choosing best-of-breed tools
  • Writing tests using dynamic languages
  • Efficient test automation
Table of Contents
    PART 1 FOUNDATIONS
  1. The promise of good tests
  2. In search of good
  3. Test doubles
  4. PART 2 CATALOG
  5. Readability
  6. Maintainability
  7. Trustworthiness
  8. PART 3 DIVERSIONS
  9. Testable design
  10. Writing tests in other JVM languages
  11. Speeding up test execution

✦ Table of Contents


Effective Unit Testing......Page 1
brief contents......Page 8
contents......Page 10
preface......Page 16
acknowledgments......Page 18
about this book......Page 20
Roadmap......Page 21
What’s next?......Page 23
Author Online......Page 24
about the cover illustration......Page 25
Part 1 Foundations......Page 26
1 The promise of good tests......Page 28
1.1 State of the union: writing better tests......Page 29
1.2 The value of having tests......Page 30
1.2.1 Factors of productivity......Page 33
1.3 Tests as a design tool......Page 35
1.3.1 Test-driven development......Page 36
1.3.2 Behavior-driven development......Page 38
1.4 Summary......Page 39
2 In search of good......Page 40
2.1 Readable code is maintainable code......Page 41
2.2 Structure helps make sense of things......Page 43
2.3 It’s not good if it’s testing the wrong things......Page 45
2.4 Independent tests run easily in solitude......Page 46
2.5 Reliable tests are reliable......Page 48
2.6 Every trade has its tools and tests are no exception......Page 50
2.7 Summary......Page 51
3 Test doubles......Page 52
3.1.1 Isolating the code under test......Page 53
3.1.2 Speeding up test execution......Page 55
3.1.3 Making execution deterministic......Page 56
3.1.5 Exposing hidden information......Page 57
3.2 Types of test doubles......Page 58
3.2.1 Test stubs are unusually short things......Page 59
3.2.2 Fake objects do it without side effects......Page 60
3.2.3 Test spies steal your secrets......Page 61
3.2.4 Mock objects object to surprises......Page 63
3.3 Guidelines for using test doubles......Page 64
3.3.2 Arrange, act, assert......Page 65
3.3.4 Choose your tools......Page 67
3.3.5 Inject your dependencies......Page 68
3.4 Summary......Page 69
Part 2 Catalog......Page 70
4 Readability......Page 72
4.1.1 Example......Page 73
4.1.2 What to do about it?......Page 74
4.2.1 Example......Page 76
4.2.2 What to do about it?......Page 79
4.2.3 Summary......Page 80
4.3.2 What to do about it?......Page 81
4.4.1 Example......Page 82
4.4.2 What to do about it?......Page 83
4.5 Split personality......Page 85
4.5.2 What to do about it?......Page 86
4.6 Split logic......Page 89
4.6.1 Example......Page 90
4.6.2 What to do about it?......Page 91
4.6.3 Summary......Page 94
4.7.1 Example......Page 95
4.7.3 Summary......Page 96
4.8.1 Example......Page 97
4.8.2 What to do about it?......Page 98
4.8.3 Summary......Page 99
4.9.1 Example......Page 100
4.10 Summary......Page 101
5 Maintainability......Page 103
5.1.1 Example......Page 104
5.1.2 What to do about it?......Page 105
5.2 Conditional logic......Page 107
5.2.2 What to do about it?......Page 108
5.2.3 Summary......Page 109
5.3.1 Example......Page 110
5.3.2 What to do about it?......Page 111
5.3.3 Summary......Page 112
5.4.1 Example......Page 113
5.4.2 What to do about it?......Page 114
5.4.3 Summary......Page 115
5.5.1 Example......Page 116
5.5.2 What to do about it?......Page 117
5.5.3 Summary......Page 118
5.6.1 Example......Page 119
5.6.2 What to do about it?......Page 120
5.6.3 Summary......Page 121
5.7.1 Example......Page 122
5.7.2 What to do about it?......Page 123
5.7.3 Summary......Page 126
5.8 Parameterized mess......Page 127
5.8.1 Example......Page 128
5.8.2 What to do about it?......Page 131
5.9 Lack of cohesion in methods......Page 133
5.9.1 Example......Page 134
5.9.2 What to do about it?......Page 135
5.9.3 Summary......Page 137
5.10 Summary......Page 138
6 Trustworthiness......Page 140
6.1.1 Example......Page 141
6.1.2 What to do about it?......Page 142
6.2.1 Example......Page 143
6.2.2 What to do about it?......Page 144
6.2.3 Summary......Page 145
6.3.1 Example......Page 146
6.3.2 What to do about it?......Page 147
6.4.1 Example(s)......Page 148
6.4.2 What to do about it?......Page 150
6.4.3 Summary......Page 151
6.5.1 Example......Page 152
6.5.2 What to do about it?......Page 153
6.6.1 Example......Page 154
6.6.2 What to do about it?......Page 155
6.6.3 Summary......Page 157
6.7.1 Example......Page 158
6.7.2 What to do about it?......Page 159
6.8 Summary......Page 160
Part 3 Diversions......Page 162
7 Testable design......Page 164
7.1.1 Modular design......Page 165
7.1.2 SOLID design principles......Page 166
7.2 Testability issues......Page 168
7.2.2 Can’t invoke a method......Page 169
7.2.5 Can’t override a method......Page 170
7.3.1 Avoid complex private methods......Page 171
7.3.2 Avoid final methods......Page 172
7.3.4 Use new with care......Page 173
7.3.5 Avoid logic in constructors......Page 174
7.3.6 Avoid the Singleton......Page 175
7.3.7 Favor composition over inheritance......Page 176
7.3.9 Avoid service lookups......Page 177
7.4 Summary......Page 179
8 Writing tests in other JVM languages......Page 181
8.1.1 General benefits......Page 182
8.1.2 Writing tests......Page 184
8.2 Writing unit tests with Groovy......Page 185
8.2.1 Simplified setup for tests......Page 186
8.3 Expressive power with BDD tools......Page 188
8.3.1 Groovy specs with easyb......Page 189
8.3.2 Spock Framework: steroids for writing more expressive tests......Page 190
8.3.3 Spock Framework’s test doubles are on steroids, too......Page 192
8.4 Summary......Page 193
9 Speeding up test execution......Page 195
9.1.1 The need for speed......Page 196
9.1.3 Profiling a build......Page 197
9.1.4 Profiling tests......Page 200
9.2.1 Don’t sleep unless you’re tired......Page 203
9.2.2 Beware the bloated base class......Page 204
9.2.3 Watch out for redundant setup and teardown......Page 206
9.2.4 Be picky about who you invite to your test......Page 207
9.2.5 Stay local, stay fast......Page 208
9.2.6 Resist the temptation to hit the database......Page 209
9.2.7 There’s no slower I/O than file I/O......Page 211
9.3 Speeding up the build......Page 212
9.3.1 Faster I/O with a RAM disk......Page 213
9.3.2 Parallelizing the build......Page 214
9.3.3 Offload to a higher-powered CPU......Page 219
9.3.4 Distribute the build......Page 221
9.4 Summary......Page 225
A.1.1 Declaring test methods......Page 227
A.1.2 JUnit test lifecycle......Page 228
A.2 JUnit assertions......Page 229
A.2.1 Asserting that an exception is thrown......Page 230
A.2.2 assertThat() and Hamcrest matchers......Page 231
B.1 Controlling test execution with runners......Page 234
B.3 Built-in rules......Page 235
B.3.2 Expected exceptions......Page 236
B.3.3 Temporary folders......Page 239
A......Page 242
C......Page 243
I......Page 244
P......Page 245
T......Page 246
W......Page 248
Back Cover......Page 249


πŸ“œ SIMILAR VOLUMES


Effective Unit Testing: A guide for Java
✍ Lasse Koskela πŸ“‚ Library πŸ“… 2013 πŸ› Manning Publications 🌐 English

<DIV><p><b>Summary</b></p><p><i>Effective Unit Testing</i> is written to show how to write good testsβ€”tests that are concise and to the point, expressive, useful, and maintainable. Inspired by Roy Osherove's bestselling <i>The Art of Unit Testing</i>, this book focuses on tools and practices specifi

Effective Unit Testing A guide for Java
✍ Lasse Koskela πŸ“‚ Library πŸ“… 2013 πŸ› Manning 🌐 English

Test the components before you assemble them into a full application, and youll get better software. For Java developers, theres now a decade of experience with well-crafted tests that anticipate problems, identify known and unknown dependencies in the code, and allow you to test components both in

Effective Unit Testing: A guide for Java
✍ Lasse Koskela πŸ“‚ Library πŸ“… 2013 πŸ› Manning 🌐 English

Effective Unit Testing teaches Java developers how to write unit tests that are concise, expressive, useful, and maintainable. Offering crisp explanations and easy-to-absorb examples, it introduces emerging techniques like behavior-driven development and specification by example. Programmers who ar

Java Unit Testing with JUnit 5: Test Dri
✍ Shekhar Gulati, Rahul Sharma πŸ“‚ Library πŸ“… 2017 πŸ› Apress 🌐 English

<p>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. <br/><br/>Unit testin

Effective Software Testing: A developer'
✍ Mauricio Aniche πŸ“‚ Library πŸ“… 2022 πŸ› Manning 🌐 English

Go beyond basic testing! Great software testing makes the entire development process more efficient. This book reveals a systemic and effective approach that will help you customize your testing coverage and catch bugs in tricky corner cases. In Effective Software Testing you will learn how to:

Effective Software Testing: A developer'
✍ MaurΓ­cio Aniche πŸ“‚ Library πŸ“… 2022 πŸ› Manning Publications Co. 🌐 English

Go beyond basic testing! Great software testing makes the entire development process more efficient, from understanding your code before you write it to catching bugs in tricky corner cases. Effective Software Testing is a hands-on guide to creating high quality tests, from your first line of code t