The art of unit testing: with examples in C#
Gespeichert in:
1. Verfasser: | |
---|---|
Format: | Buch |
Sprache: | English |
Veröffentlicht: |
Shelter Island, NY
Manning
2014
|
Ausgabe: | 2. ed. |
Schlagworte: | |
Online-Zugang: | Inhaltsverzeichnis |
Beschreibung: | XXVI, 266 S. Ill., graph. Darst. |
ISBN: | 9781617290893 |
Internformat
MARC
LEADER | 00000nam a2200000zc 4500 | ||
---|---|---|---|
001 | BV041629116 | ||
003 | DE-604 | ||
005 | 20140801 | ||
007 | t | ||
008 | 140205s2014 ad|| |||| 00||| eng d | ||
020 | |a 9781617290893 |c (pbk.) No price |9 978-1-617-29089-3 | ||
035 | |a (OCoLC)873446196 | ||
035 | |a (DE-599)HBZHT017786048 | ||
040 | |a DE-604 |b ger | ||
041 | 0 | |a eng | |
049 | |a DE-573 |a DE-91G | ||
084 | |a ST 232 |0 (DE-625)143619: |2 rvk | ||
084 | |a ST 233 |0 (DE-625)143620: |2 rvk | ||
084 | |a DAT 358f |2 stub | ||
084 | |a DAT 330f |2 stub | ||
100 | 1 | |a Osherove, Roy |e Verfasser |0 (DE-588)142933740 |4 aut | |
245 | 1 | 0 | |a The art of unit testing |b with examples in C# |c Roy Osherove |
250 | |a 2. ed. | ||
264 | 1 | |a Shelter Island, NY |b Manning |c 2014 | |
300 | |a XXVI, 266 S. |b Ill., graph. Darst. | ||
336 | |b txt |2 rdacontent | ||
337 | |b n |2 rdamedia | ||
338 | |b nc |2 rdacarrier | ||
650 | 0 | 7 | |a C sharp |0 (DE-588)4616843-6 |2 gnd |9 rswk-swf |
650 | 0 | 7 | |a Softwaretest |0 (DE-588)4132652-0 |2 gnd |9 rswk-swf |
650 | 0 | 7 | |a Komponententest |0 (DE-588)4674453-8 |2 gnd |9 rswk-swf |
653 | |a Computer software--Testing. | ||
653 | |a Computer software--Development. | ||
653 | |a Microsoft .NET. | ||
689 | 0 | 0 | |a Komponententest |0 (DE-588)4674453-8 |D s |
689 | 0 | 1 | |a C sharp |0 (DE-588)4616843-6 |D s |
689 | 0 | |5 DE-604 | |
689 | 1 | 0 | |a Softwaretest |0 (DE-588)4132652-0 |D s |
689 | 1 | |8 1\p |5 DE-604 | |
856 | 4 | 2 | |m HBZ Datenaustausch |q application/pdf |u http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027070064&sequence=000002&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |3 Inhaltsverzeichnis |
999 | |a oai:aleph.bib-bvb.de:BVB01-027070064 | ||
883 | 1 | |8 1\p |a cgwrk |d 20201028 |q DE-101 |u https://d-nb.info/provenance/plan#cgwrk |
Datensatz im Suchindex
_version_ | 1804151846855507968 |
---|---|
adam_text | Titel: The art of unit testing
Autor: Osherove, Roy
Jahr: 2014
contents
foreword, to the second edition xv
foreword to the first edition xvii
preface xix
acknowledgments xxi
about this book xxii
about the cover illustration xxvi
Part 1 Getting started ............................................ 1
/ The basics of unit testing 3
*¦ 1.1 Defining unit testing, step by step 4
The importance of writing good unit tests 5m We ve all written
unit tests (sort of) 5
1.2 Properties of a good unit test 6
1.3 Integration tests 7
Drawbacks of nonautomated integration tests compared
to automated unit tests 9
1.4 What makes unit tests good 11
1.5 A simple unit test example 11
1.6 Test-driven development 14
ix
X
CONTENTS
1.7 The three core skills of successful TDD 17
1.8 Summary 17
A first
jC-J 21
unit test 19
2.1 Frameworks for unit testing 20
What unit testing frameworks offer 20
The xUnit frameworks 22
2.2 Introducing the LogAn project 22
2.3 First steps with NUnit 23
Installing NUnit 23 • Loading up the solution 25
Using the NUnit attributes in your code 27
2.4 Writing your first test 27
The Assert class 28* Running your first test with NUnit 29
Adding some positive tests 30 * From red to green:
passing the tests 31 * Test code styling 31
2.5 Refactoring to parameterized tests 31
2.6 More NUnit attributes 33
Setup and teardown 34* Checking for expected exceptions 36
Ignoring tests 39* NUnit s fluent syntax 39
Setting test categories 40
2.7 Testing results that are system state changes instead of
return values 40
2.8 Summary 44
3 Using stubs to break dependencies 49
3.1 Introducing stubs 50
3.2 Identifying a filesystem dependency in LogAn 50
3.3 Determining how to easily test LogAnalyzer 51
3.4 Refactoring your design to be more testable 53
Extract an interface to allow replacing underlying
implementation 55 * Dependency injection: inject a fake
implementation into a unit under test 57 * Inject a fake
at the constructor level (constructor injection) 57
Simulating exceptions from fakes 61 * Injecting a fake
as a property get or set 61 * Injecting a fake just before
a method call 63
Par i 2 Core techniques
47
CONTENTS
3.5 Variations on refactoring techniques 69
Using Extract and Override to create fake results 70
3.6 Overcoming the encapsulation problem 71
Using internal and [InternalsVisibleTo] 72* Using the
[Conditional] attribute 72* Using #if and #endif with
conditional compilation 73
3.7 Summary 73
Interaction testing using mock objects 75
4.1 Value-based vs. state-based vs. interaction testing 76
4.2 The difference between mocks and stubs 78
4.3 A simple handwritten mock example 79
4.4 Using a mock and a stub together 81
4.5 One mock per test 85
4.6 Fake chains: stubs that produce mocks or other stubs
4.7 The problems with handwritten mocks and stubs 87
4.8 Summary 88
Isolation (mocking) frameworks 90
5.1 Why use isolation frameworks? 91
5.2 Dynamically creating a fake object 93
Introducing NSubstitute into your tests 93 * Replacing a
handwritten fake object with a dynamic one 94
5.3 Simulating fake values 96
A mock, a stub, and a priest walk into a test 97
5.4 Testing for event-related activities 102
Testing an event listener 102 * Testing whether an
event was triggered 103
5.5 Current isolation frameworks for .NET 104
5.6 Advantages and traps of isolation frameworks 106
Traps to avoid when using isolation frameworks 106
Unreadable test code 106 * Verifying the wrong things 106
Having more than one mock per test 107
Overspecifying the tests 107
5.7 Summary 107
CONTENTS
Digging deeper into isolation frameworks 109
6.1 Constrained and unconstrained frameworks 110
Constrained frameworks 110 ¦ Unconstrained frameworks 110
How profiler-based unconstrained frameworks work 112
6.2 Values of good isolation frameworks 114
6.3 Features supporting future-proofing and usability 114
Recursive fakes 115 ¦ Ignored arguments by default 115
Wide faking 116 1 Nonstrict behavior of fakes 116
Nonstrict mocks 117
6.4 Isolation framework design antipatterns 117
Concept confusion 118 • Record and replay 119
Sticky behavior 120 ¦ Complex syntax 120
6.5 Summary 121
Test hierarchies and organization 125
7.1 Automated builds running automated tests 126
Anatomy of a build script 127¦ Triggering builds
and integration 128
7.2 Mapping out tests based on speed and type 130
The human factor when separating unit from integration tests 130
The safe green zone 131
7.3 Ensuring tests are part of source control 131
7.4 Mapping test classes to code under test 132
Mapping tests to projects 132 * Mapping tests to classes 132
Mapping tests to specific unit of work method entry points 133
7.5 Cross-cutting concerns injection 134
7.6 Building a test API for your application 136
Using test class inheritance patterns 136 ¦ Creatingtest utility classes
and methods 148 ¦ Making your API known to developers 149
7.7 Summary 149
The pillars of good unit tests 151
8.1 Writing trustworthy tests 152
Deciding when to remove or change tests 152 ¦ Avoiding logic
in tests 156 * Testing only one concern 158 ¦ Separate unit
from integration tests 159 * Assuring code review
with code coverage 159
CONTENTS
xiii
8.2 Writing maintainable tests 161
Testing private or protected methods 161
Removing duplication 163 ¦ Using setup methods
in a maintainable manner 166 ¦ Enforcing test isolation 169
Avoiding multiple asserts on different concerns 174
Comparing objects 176 ¦ Avoiding overspecification 178
8.3 Writing readable tests 180
Naming unit tests 181 ¦ Naming variables 181
Asserting yourself with meaning 182 ¦ Separating asserts
from actions 183 ¦ Setting up and tearing down 184
8.4 Summary 184
Integrating unit testing into the organization 189
9.1 Steps to becoming an agent of change 190
Be prepared for the tough questions 190¦ Convince insiders:
champions and blockers 190 ¦ Identify possible entry points 191
9.2 Ways to succeed 193
Guerrilla implementation (bottom up) 193
Convincing management (top down) 193 ¦ Getting an outside
champion 194 ¦ Making progress visible 194 * Aiming for
specific goals 196 ¦ Realizing that there will be hurdles 197
9.4 Influence factors 199
9.5 Tough questions and answers 200
How much time will unit testing add to the current process ? 200
Will my QAjob be at risk because of unit testing? 202
How do we know unit tests are actually working? 202
Is there proof that unit testing helps ? 203 ¦ Why is the QA
department still finding bugs? 203 * We have lots of code without
tests: where do we start ? 204 ¦ We work in several languages: is
unit testing feasible? 204 ¦ What if we develop a combination of
software and hardware? 204 ¦ How can we know we don t have
bugs in our tests ? 205 * My debugger shows that my code works;
why do I need tests? 205 ¦ Must we do TDD-style coding? 205
Part 4 Design and process
187
9.3 Ways to fail 197
Lack of a driving force 197¦ Lack of political support 198
Bad implementations and first impressions 198
Lack of team support 198
9.6 Summary 205
CONTENTS
Working with legacy code 207
10.1 Where do you start adding tests? 208
10.2 Choosing a selection strategy 209
Pros and cons of the easy-first strategy 210 ¦ Pros and cons
of the hard-first strategy 210
10.3 Writing integration tests before refactoring 211
10.4 Important tools for legacy code unit testing 212
Isolate dependencies easily with unconstrained
isolation frameworks 212* UseJMockit for Java legacy code 213
Use Vise while refactoring your Java code 215 ¦ Use acceptance
tests bejore you refactor 216 ¦ Read Michael Feathers s book
on legacy code 216 * Use NDepend to investigate your
production code 216 ¦ Use ReSharper to navigate and refactor
production code 217 ¦ Detect duplicate code (and bugs) with
Simian and TeamCity 218
10.5 Summary 218
Design and testability 219
11.1 Why should I care about testability in my design? 219
11.2 Design goals for testability 220
Make methods virtual by default 221 ¦ Use interface-based
designs 222 ¦ Make classes nonsealed by default 222
Avoid instantiating concrete classes inside methods with logic 222
Avoid direct calls to static methods 222 ¦ Avoid constructors
and static constructors that do logic 223 * Separate singleton logic
from singleton holders 223
11.3 Pros and cons of designing for testability 224
Amount of work 225 * Complexity 225
Exposing sensitive IP 226 ¦ Sometimes you can t 226
11.4 Alternatives to designing for testability 226
Design arguments and dynamically typed languages 227
11.5 Example of a hard-to-test design 228
11.6 Summary 232
11.7 Additional resources 232
appendix Tools and frameworks 234
index 253
|
any_adam_object | 1 |
author | Osherove, Roy |
author_GND | (DE-588)142933740 |
author_facet | Osherove, Roy |
author_role | aut |
author_sort | Osherove, Roy |
author_variant | r o ro |
building | Verbundindex |
bvnumber | BV041629116 |
classification_rvk | ST 232 ST 233 |
classification_tum | DAT 358f DAT 330f |
ctrlnum | (OCoLC)873446196 (DE-599)HBZHT017786048 |
discipline | Informatik |
edition | 2. ed. |
format | Book |
fullrecord | <?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://www.loc.gov/MARC21/slim"><record><leader>01789nam a2200469zc 4500</leader><controlfield tag="001">BV041629116</controlfield><controlfield tag="003">DE-604</controlfield><controlfield tag="005">20140801 </controlfield><controlfield tag="007">t</controlfield><controlfield tag="008">140205s2014 ad|| |||| 00||| eng d</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9781617290893</subfield><subfield code="c">(pbk.) No price</subfield><subfield code="9">978-1-617-29089-3</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(OCoLC)873446196</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(DE-599)HBZHT017786048</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">DE-604</subfield><subfield code="b">ger</subfield></datafield><datafield tag="041" ind1="0" ind2=" "><subfield code="a">eng</subfield></datafield><datafield tag="049" ind1=" " ind2=" "><subfield code="a">DE-573</subfield><subfield code="a">DE-91G</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">ST 232</subfield><subfield code="0">(DE-625)143619:</subfield><subfield code="2">rvk</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">ST 233</subfield><subfield code="0">(DE-625)143620:</subfield><subfield code="2">rvk</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">DAT 358f</subfield><subfield code="2">stub</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">DAT 330f</subfield><subfield code="2">stub</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Osherove, Roy</subfield><subfield code="e">Verfasser</subfield><subfield code="0">(DE-588)142933740</subfield><subfield code="4">aut</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">The art of unit testing</subfield><subfield code="b">with examples in C#</subfield><subfield code="c">Roy Osherove</subfield></datafield><datafield tag="250" ind1=" " ind2=" "><subfield code="a">2. ed.</subfield></datafield><datafield tag="264" ind1=" " ind2="1"><subfield code="a">Shelter Island, NY</subfield><subfield code="b">Manning</subfield><subfield code="c">2014</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">XXVI, 266 S.</subfield><subfield code="b">Ill., graph. Darst.</subfield></datafield><datafield tag="336" ind1=" " ind2=" "><subfield code="b">txt</subfield><subfield code="2">rdacontent</subfield></datafield><datafield tag="337" ind1=" " ind2=" "><subfield code="b">n</subfield><subfield code="2">rdamedia</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="b">nc</subfield><subfield code="2">rdacarrier</subfield></datafield><datafield tag="650" ind1="0" ind2="7"><subfield code="a">C sharp</subfield><subfield code="0">(DE-588)4616843-6</subfield><subfield code="2">gnd</subfield><subfield code="9">rswk-swf</subfield></datafield><datafield tag="650" ind1="0" ind2="7"><subfield code="a">Softwaretest</subfield><subfield code="0">(DE-588)4132652-0</subfield><subfield code="2">gnd</subfield><subfield code="9">rswk-swf</subfield></datafield><datafield tag="650" ind1="0" ind2="7"><subfield code="a">Komponententest</subfield><subfield code="0">(DE-588)4674453-8</subfield><subfield code="2">gnd</subfield><subfield code="9">rswk-swf</subfield></datafield><datafield tag="653" ind1=" " ind2=" "><subfield code="a">Computer software--Testing.</subfield></datafield><datafield tag="653" ind1=" " ind2=" "><subfield code="a">Computer software--Development.</subfield></datafield><datafield tag="653" ind1=" " ind2=" "><subfield code="a">Microsoft .NET.</subfield></datafield><datafield tag="689" ind1="0" ind2="0"><subfield code="a">Komponententest</subfield><subfield code="0">(DE-588)4674453-8</subfield><subfield code="D">s</subfield></datafield><datafield tag="689" ind1="0" ind2="1"><subfield code="a">C sharp</subfield><subfield code="0">(DE-588)4616843-6</subfield><subfield code="D">s</subfield></datafield><datafield tag="689" ind1="0" ind2=" "><subfield code="5">DE-604</subfield></datafield><datafield tag="689" ind1="1" ind2="0"><subfield code="a">Softwaretest</subfield><subfield code="0">(DE-588)4132652-0</subfield><subfield code="D">s</subfield></datafield><datafield tag="689" ind1="1" ind2=" "><subfield code="8">1\p</subfield><subfield code="5">DE-604</subfield></datafield><datafield tag="856" ind1="4" ind2="2"><subfield code="m">HBZ Datenaustausch</subfield><subfield code="q">application/pdf</subfield><subfield code="u">http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027070064&sequence=000002&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA</subfield><subfield code="3">Inhaltsverzeichnis</subfield></datafield><datafield tag="999" ind1=" " ind2=" "><subfield code="a">oai:aleph.bib-bvb.de:BVB01-027070064</subfield></datafield><datafield tag="883" ind1="1" ind2=" "><subfield code="8">1\p</subfield><subfield code="a">cgwrk</subfield><subfield code="d">20201028</subfield><subfield code="q">DE-101</subfield><subfield code="u">https://d-nb.info/provenance/plan#cgwrk</subfield></datafield></record></collection> |
id | DE-604.BV041629116 |
illustrated | Illustrated |
indexdate | 2024-07-10T01:01:19Z |
institution | BVB |
isbn | 9781617290893 |
language | English |
oai_aleph_id | oai:aleph.bib-bvb.de:BVB01-027070064 |
oclc_num | 873446196 |
open_access_boolean | |
owner | DE-573 DE-91G DE-BY-TUM |
owner_facet | DE-573 DE-91G DE-BY-TUM |
physical | XXVI, 266 S. Ill., graph. Darst. |
publishDate | 2014 |
publishDateSearch | 2014 |
publishDateSort | 2014 |
publisher | Manning |
record_format | marc |
spelling | Osherove, Roy Verfasser (DE-588)142933740 aut The art of unit testing with examples in C# Roy Osherove 2. ed. Shelter Island, NY Manning 2014 XXVI, 266 S. Ill., graph. Darst. txt rdacontent n rdamedia nc rdacarrier C sharp (DE-588)4616843-6 gnd rswk-swf Softwaretest (DE-588)4132652-0 gnd rswk-swf Komponententest (DE-588)4674453-8 gnd rswk-swf Computer software--Testing. Computer software--Development. Microsoft .NET. Komponententest (DE-588)4674453-8 s C sharp (DE-588)4616843-6 s DE-604 Softwaretest (DE-588)4132652-0 s 1\p DE-604 HBZ Datenaustausch application/pdf http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027070064&sequence=000002&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA Inhaltsverzeichnis 1\p cgwrk 20201028 DE-101 https://d-nb.info/provenance/plan#cgwrk |
spellingShingle | Osherove, Roy The art of unit testing with examples in C# C sharp (DE-588)4616843-6 gnd Softwaretest (DE-588)4132652-0 gnd Komponententest (DE-588)4674453-8 gnd |
subject_GND | (DE-588)4616843-6 (DE-588)4132652-0 (DE-588)4674453-8 |
title | The art of unit testing with examples in C# |
title_auth | The art of unit testing with examples in C# |
title_exact_search | The art of unit testing with examples in C# |
title_full | The art of unit testing with examples in C# Roy Osherove |
title_fullStr | The art of unit testing with examples in C# Roy Osherove |
title_full_unstemmed | The art of unit testing with examples in C# Roy Osherove |
title_short | The art of unit testing |
title_sort | the art of unit testing with examples in c |
title_sub | with examples in C# |
topic | C sharp (DE-588)4616843-6 gnd Softwaretest (DE-588)4132652-0 gnd Komponententest (DE-588)4674453-8 gnd |
topic_facet | C sharp Softwaretest Komponententest |
url | http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=027070064&sequence=000002&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |
work_keys_str_mv | AT osheroveroy theartofunittestingwithexamplesinc |