Muutke küpsiste eelistusi

E-raamat: Unit Testing Principles, Practices, and Patterns

4.57/5 (1138 hinnangut Goodreads-ist)
  • Formaat: 304 pages
  • Ilmumisaeg: 06-Jan-2020
  • Kirjastus: Manning Publications
  • Keel: eng
  • ISBN-13: 9781638350293
  • Formaat - EPUB+DRM
  • Hind: 43,42 €*
  • * hind on lõplik, st. muud allahindlused enam ei rakendu
  • Lisa ostukorvi
  • Lisa soovinimekirja
  • See e-raamat on mõeldud ainult isiklikuks kasutamiseks. E-raamatuid ei saa tagastada.
  • Formaat: 304 pages
  • Ilmumisaeg: 06-Jan-2020
  • Kirjastus: Manning Publications
  • Keel: eng
  • ISBN-13: 9781638350293

DRM piirangud

  • Kopeerimine (copy/paste):

    ei ole lubatud

  • Printimine:

    ei ole lubatud

  • Kasutamine:

    Digitaalõiguste kaitse (DRM)
    Kirjastus on väljastanud selle e-raamatu krüpteeritud kujul, mis tähendab, et selle lugemiseks peate installeerima spetsiaalse tarkvara. Samuti peate looma endale  Adobe ID Rohkem infot siin. E-raamatut saab lugeda 1 kasutaja ning alla laadida kuni 6'de seadmesse (kõik autoriseeritud sama Adobe ID-ga).

    Vajalik tarkvara
    Mobiilsetes seadmetes (telefon või tahvelarvuti) lugemiseks peate installeerima selle tasuta rakenduse: PocketBook Reader (iOS / Android)

    PC või Mac seadmes lugemiseks peate installima Adobe Digital Editionsi (Seeon tasuta rakendus spetsiaalselt e-raamatute lugemiseks. Seda ei tohi segamini ajada Adober Reader'iga, mis tõenäoliselt on juba teie arvutisse installeeritud )

    Seda e-raamatut ei saa lugeda Amazon Kindle's. 

Unit Testing Principles, Patterns and Practices shows you how to refine your existing unit tests by implementing modern best practices. You'll learn to spot which tests are performing, which need refactoring, and which need to be deleted entirely! Upgrade your testing suite with new testing styles, good patterns, and reliable automated testing.

Unit Testing Principles, Practices and Patterns is a practical guide to modern unit testing best practices. Microsoft MVP Vladimir Khorikov takes you hands-on with examples of the ideal unit test and unit testing practices, building your skills step by step on a solid foundation.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.



Summary

Unit Testing Principles, Patterns and Practices shows you how to refine your existing unit tests by implementing modern best practices. You&;ll learn to spot which tests are performing, which need refactoring, and which need to be deleted entirely! Upgrade your testing suite with new testing styles, good patterns, and reliable automated testing.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Great testing practices will help maximize your project quality and delivery speed. Wrong tests will break your code, multiply bugs, and increase time and costs. You owe it to yourself&;and your projects&;to learn how to do excellent unit testing to increase your productivity and the end-to-end quality of your software.

About the book

Unit Testing Principles, Patterns and Practices teaches you to design and write tests that target the domain model and other key areas of your code base. In this clearly written guide, you learn to develop professional-quality test suites, safely automate your testing process, and integrate testing throughout the application life cycle. As you adopt a testing mindset, you&;ll be amazed at how better tests cause you to write better code.

What's inside

    Universal guidelines to assess any unit test
    Testing to identify and avoid anti-patterns
    Refactoring tests along with the production code
    Using integration tests to verify the whole system

About the reader

For readers who know the basics of unit testing. The C# examples apply to any language.

About the author

Vladimir Khorikov is an author, blogger, and Microsoft MVP. He has mentored numerous teams on the ins and outs of unit testing.

Table of Contents:

PART 1 THE BIGGER PICTURE

1 ¦ The goal of unit testing

2 ¦ What is a unit test?

3 ¦ The anatomy of a unit test

PART 2 MAKING YOUR TESTS WORK FOR YOU

4 ¦ The four pillars of a good unit test

5 ¦ Mocks and test fragility

6 ¦ Styles of unit testing

7 ¦ Refactoring toward valuable unit tests

PART 3 INTEGRATION TESTING

8 ¦ Why integration testing?

9 ¦ Mocking best practices

10 ¦ Testing the database

PART 4 UNIT TESTING ANTI-PATTERNS

11 ¦ Unit testing anti-patterns
Preface xiv
Acknowledgments xv
About This Book xvi
About The Author xix
About The Cover Illustration xx
Part 1 The Bigger Picture 1(64)
1 The goal of unit testing
3(17)
1.1 The current state of unit testing
4(1)
1.2 The goal of unit testing
5(3)
What makes a good or bad test?
7(1)
1.3 Using coverage metrics to measure test suite quality
8(7)
Understanding the code coverage metric
9(1)
Understanding the branch coverage metric
10(2)
Problems with coverage metrics
12(3)
Aiming at a particular coverage number
15(1)
1.4 What makes a successful test suite?
15(2)
It's integrated into the development cycle
16(1)
It targets only the most important parts of your code base
16(1)
It provides maximum value with minimum maintenance costs
17(1)
1.5 What you will learn in this book
17(3)
2 What is a unit test?
20(21)
2.1 The definition of "unit test"
21(9)
The isolation issue: The London take
21(6)
The isolation issue: The classical take
27(3)
2.2 The classical and London schools of unit testing
30(4)
How the classical and London schools handle dependencies
30(4)
2.3 Contrasting the classical and London schools of unit testing
34(3)
Unit testing one class at a time
34(1)
Unit testing a large graph of interconnected classes
35(1)
Revealing the precise bug location
36(1)
Other differences between the classical and London schools
36(1)
2.4 Integration tests in the two schools
37(4)
End-to-end tests are a subset of integration tests
38(3)
3 The anatomy of a unit test
41(24)
3.1 How to structure a unit test
42(7)
Using the AAA pattern
42(1)
Avoid multiple arrange, act, and assert sections
43(1)
Avoid if statements in tests
44(1)
How large should each section be?
45(2)
How many assertions should the assert section hold?
47(1)
What about the teardown phase?
47(1)
Differentiating the system under test
47(1)
Dropping the arrange, act, and assert comments from tests
48(1)
3.2 Exploring the xUnit testing framework
49(1)
3.3 Reusing test fixtures between tests
50(4)
High coupling between tests is an anti-pattern
52(1)
The use of constructors in tests diminishes test readability
52(1)
A better way to reuse test fixtures
52(2)
3.4 Naming a unit test
54(4)
Unit test naming guidelines
56(1)
Example: Renaming a test toward the guidelines
56(2)
3.5 Refactoring to parameterized tests
58(4)
Generating data for parameterized tests
60(2)
3.6 Using an assertion library to further improve test readability
62(3)
Part 2 Making Your Tests Work For You 65(118)
4 The four pillars of a good unit test
67(25)
4.1 Diving into the four pillars of a good unit test
68(8)
The first pillar: Protection against regressions
68(1)
The second pillar: Resistance to refactoring
69(2)
What causes false positives?
71(3)
Aim at the end result instead of implementation details
74(2)
4.2 The intrinsic connection between the first two attributes
76(3)
Maximizing test accuracy
76(2)
The importance of false positives and false negatives: The dynamics
78(1)
4.3 The third and fourth pillars: Fast feedback and maintainability
79(1)
4.4 In search of an ideal test
80(7)
Is it possible to create an ideal test?
81(1)
Extreme case #1: End-to-end tests
81(1)
Extreme case #2: Trivial tests
82(1)
Extreme case #3: Brittle tests
83(1)
In search of an ideal test: The results
84(3)
4.5 Exploring well-known test automation concepts
87(5)
Breaking down the Test Pyramid
87(2)
Choosing between black-box and white-box testing
89(3)
5 Mocks and test fragility
92(27)
5.1 Differentiating mocks from stubs
93(6)
The types of test doubles
93(1)
Mock (the tool) vs. mock (the test double)
94(2)
Don't assert interactions with stubs
96(1)
Using mocks and stubs together
97(1)
How mocks and stubs relate to commands and queries
97(2)
5.2 Observable behavior vs. implementation details
99(7)
Observable behavior is not the same as a public API
99(1)
Leaking implementation details: An example with an operation
100(3)
Well-designed API and encapsulation
103(1)
Leaking implementation details: An example with state
104(2)
5.3 The relationship between mocks and test fragility
106(8)
Defining hexagonal architecture
106(4)
Intra-system vs. intersystem communications
110(1)
Intra-system vs. inter-system communications: An example
111(3)
5.4 The classical vs. London schools of unit testing, revisited
114(5)
Not all out-of-process dependencies should be mocked out
115(1)
Using mocks to verify behavior
116(3)
6 Styles of unit testing
119(32)
6.1 The three styles of unit testing
120(3)
Defining the output-based style
120(1)
Defining the state-based style
121(1)
Defining the communication-based style
122(1)
6.2 Comparing the three styles of unit testing
123(5)
Comparing the styles using the metrics of protection against regressions and feedback speed
124(1)
Comparing the styles using the metric of resistance to refactoring
124(1)
Comparing the styles using the metric of maintainability
125(2)
Comparing the styles: The results
127(1)
6.3 Understanding functional architecture
128(7)
What is functional programming?
128(4)
What is functional architecture?
132(1)
Comparing functional and hexagonal architectures
133(2)
6.4 Transitioning to functional architecture and output-based testing
135(11)
Introducing an audit system
135(2)
Using mocks to decouple tests from the filesystem
137(3)
Refactoring toward functional architecture
140(6)
Looking forward to further developments
146(1)
6.5 Understanding the drawbacks of functional architecture
146(5)
Applicability of functional architecture
147(1)
Performance drawbacks
148(1)
Increase in the code base size
149(2)
7 Refactoring toward valuable unit tests
151(32)
7.1 Identifying the code to refactor
152(6)
The four types of code
152(3)
Using the Humble Object pattern to split overcomplicated code
155(3)
7.2 Refactoring toward valuable unit tests
158(9)
Introducing a customer management system
158(2)
Take 1: Making implicit dependencies explicit
160(1)
Take 2: Introducing an application services layer
160(3)
Take 3: Removing complexity from the application service
163(1)
Take 4: Introducing a new Company class
164(3)
7.3 Analysis of optimal unit test coverage
167(2)
Testing the domain layer and utility code
167(1)
Testing the code from the other three quadrants
168(1)
Should you test preconditions?
169(1)
7.4 Handling conditional logic in controllers
169(9)
Using the CanExecute/Execute pattern
172(3)
Using domain events to track changes in the domain model
175(3)
7.5 Conclusion
178(5)
Part 3 Integration Testing 183(74)
8 Why integration testing?
185(31)
8.1 What is an integration test?
186(4)
The role of integration tests
186(1)
The Test Pyramid revisited
187(1)
Integration testing vs. failing fast
188(2)
8.2 Which out-of-process dependencies to test directly
190(3)
The two types of out-of-process dependencies
190(1)
Working with both managed and unmanaged dependencies
191(1)
What if you can't use a real database in integration tests?
192(1)
8.3 Integration testing: An example
193(4)
What scenarios to test?
194(1)
Categorizing the database and the message bus
195(1)
What about end-to-end testing?
195(1)
Integration testing: The first try
196(1)
8.4 Using interfaces to abstract dependencies
197(3)
Interfaces and loose coupling
198(1)
Why use interfaces for out-of-process dependencies?
199(1)
Using interfaces for in-process dependencies
199(1)
8.5 Integration testing best practices
200(5)
Making domain model boundaries explicit
200(1)
Reducing the number of layers
200(2)
Eliminating circular dependencies
202(2)
Using multiple act sections in a test
204(1)
8.6 How to test logging functionality
205(8)
Should you test logging?
205(2)
How should you test logging?
207(5)
How much logging is enough?
212(1)
How do you pass around logger instances?
212(1)
8.7 Conclusion
213(3)
9 Mocking best practices
216(13)
9.1 Maximizing mocks' value
217(8)
Verifying interactions at the system edges
219(3)
Replacing mocks with spies
222(2)
What about IDomainLogger?
224(1)
9.2 Mocking best practices
225(4)
Mocks are for integration tests only
225(1)
Not just one mock per test
225(1)
Verifying the number of calls
226(1)
Only mock types that you own
227(2)
10 Testing the database
229(28)
10.1 Prerequisites for testing the database
230(4)
Keeping the database in the source control system
230(1)
Reference data is part of the database schema
231(1)
Separate instance for every developer
232(1)
State-based vs. migration-based database delivery
232(2)
10.2 Database transaction management
234(9)
Managing database transactions in production code
235(7)
Managing database transactions in integration tests
242(1)
10.3 Test data life cycle
243(3)
Parallel vs. sequential test execution
243(1)
Clearing data between test runs
244(2)
Avoid in-memory databases
246(1)
10.4 Reusing code in test sections
246(6)
Reusing code in arrange sections
246(3)
Reusing code in act sections
249(1)
Reusing code in assert sections
250(1)
Does the test create too many database transactions?
251(1)
10.5 Common database testing questions
252(2)
Should you test reads?
252(1)
Should you test repositories?
253(1)
10.6 Conclusion
254(3)
Part 3 Unit Testing Anti-Patterns 257(18)
11 Unit testing anti-patterns
259(16)
11.1 Unit testing private methods
260(3)
Private methods and test fragility
260(1)
Private methods and insufficient coverage
260(1)
When testing private methods is acceptable
261(2)
11.2 Exposing private state
263(1)
11.3 Leaking domain knowledge to tests
264(2)
11.4 Code pollution
266(2)
11.5 Mocking concrete classes
268(3)
11.6 Working with time
271(2)
Time as an ambient context
271(1)
Time as an explicit dependency
272(1)
11.7 Conclusion
273(2)
Index 275
Vladimir Khorikov is an author, blogger, and Microsoft MVP. He has been developing software professionally for over ten years, and has mentored numerous teams on the ins and outs of unit testing.