-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreface.txt
69 lines (48 loc) · 3.84 KB
/
preface.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[preface]
Preface
-------
So you want to write great tests? Ah, so do I! :) I have some experience in writing tests, and I would like to share it with you.
Stay focused, stay sharp, distill what you read through your own experiences, and choose what seems right and valuable for you.
[float]
==== The Idea
The idea behind this book is to present test code snippets and discuss ways of making them better.
All examples discussed in this book come from real code of real applications. I haven't made them up. They are real. From thousands of tests I have seen I have selected these which illustrate some typical errors or imperfections which I frequently encounter while doing code reviews (or pondering over my own code!).
Some of the code examples were obfuscated in order to '"protect the innocents"'. ;) Many were significantly truncated, so only their '"essence"' was left, and all the cluttering was removed. This makes the examples easier to understand but at the same time it makes some of the discussed issues look not so important. However they *are* important in real life scenarios, where you have to deal with numerous much more complex tests (or the same issues were repeated in numerous tests).
Even though the title of this book mentions '"bad tests"' in fact only few of the tests presented here are really bad. The most of them is rather imperfect. However for the sake of marketing impact I decided to go with '"bad tests"' on the cover. :)
[float]
==== SUT and Assertions
From time to time I use term 'SUT' which denotes 'System Under Test', that is *the thing* being tested. The SUT can vary in size. For unit tests it is usually a class, for integration tests it might be a class, a layer or a module, and for end-to-end tests it is the whole system.
Throughout the book I often use FEST Fluent Assertions{empty}pass:[]footnote:[https://github.com/alexruiz/fest-assert-2.x/wiki] (e.g. +assertThat(...)+) instead of those provided by JUnit or TestNG (e.g. +assertEquals(...)+). After writing thousands of tests (of each kind) I can say they are simply better.
[float]
==== Icons
The following icons appear within the text:
TIP: A helpful tip.
NOTE: An additional note.
WARNING: Warning, danger ahead!
All three icons were designed by http://www.webdesignerdepot.com/[Webdesigner Depot].
[float]
=== What I Expect From You
To really benefit from reading this book you should:
* have some experience in writing tests, especially unit tests,
* know a testing framework; preferably TestNG or JUnit, but any other will also be fine,
* be interested in improving your tests-writing skills,
* understand the value of clean test code.
TIP: You could gain some of the required knowledge by reading my other books (visit http://practicalunittesting.com).
[float]
==== Contributors
Thanks to Bartosz Ocytko, Martin, Bartek Zdanowski, Jakub Nabrdalik, Tomasz Borek TODO who else?,
ifndef::print[]
[float]
==== Why This Book is For Free?
This book is for free because I decided so. :) This is possible thanks to many of you, who have bought my previous books from the http://practicalunittesting.com['"Practical Unit Testing"'] serie. Thank you very much!
By giving this book for free I would also like to pay my debts to the community. I have gained a lot from many bloggers, open-source contributors and forums participants. Thanks to your engagement and the willingness to share your knowledge and experience I'm a better developer today, and I can benefit from many open-source tools. Thank you very much!
Least but not least, it is real fun to give gifts. And I'm enjoying it very much! :)
endif::print[]
ifdef::print[]
[float]
==== Free e-Book Available
Visit http://practicalunittesting.com to download a free e-book version of this book.
endif::print[]
[float]
==== Book Site
Please visit the http://practicalunittesting.com[official book site] for news and information on downloadable extras etc.