وبلاگ بلیان

الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)

xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)

جلد کتاب الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)

معرفی کتاب «الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)» (با عنوان لاتین xUnit Test Patterns: Refactoring Test Code (The Addison-Wesley Signature Series)) نوشتهٔ Zhao، Xiran Jay و Gerard Meszaros، منتشرشده توسط نشر Addison-Wesley Professional; Addison-Wesley در سال 2007. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

کتاب «الگوهای آزمون xUnit: بازسازی کد آزمون» (xUnit Test Patterns: Refactoring Test Code) نوشته‌ی جرارد مزاروش، یکی از تأثیرگذارترین و جامع‌ترین منابع در حوزه‌ی آزمون خودکار نرم‌افزار به‌شمار می‌رود. این کتاب که در سال ۲۰۰۷ توسط انتشارات معتبر ادیسون-وِسلی (Addison-Wesley) در مجموعه‌ی امضای خود منتشر شده، با تمرکز بر الگوها و بوهای بد (smells) در کد آزمون، به توسعه‌دهندگان می‌آموزد که چگونه آزمون‌هایی بنویسند که نه‌تنها قابل‌اعتماد و تکرارپذیر باشند، بلکه به‌مرور زمان نیز به‌سادگی قابل نگهداری و بازسازی باشند. این کتاب که برنده‌ی جایزه‌ی جولت (Jolt Productivity Award) در بخش بهترین کتاب فنی شده است، مرجعی بی‌نظیر برای هر کسی است که به‌دنبال ارتقای کیفیت فرایند آزمون خود در پروژه‌های نرم‌افزاری است.

دربارهٔ کتاب «الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)»

موضوع اصلی این کتاب، ارائه‌ی مجموعه‌ای از الگوهای اثبات‌شده برای نوشتن آزمون‌های خودکار با استفاده از خانواده‌ی فریم‌ورک‌های xUnit مانند جی‌یونیت (JUnit) و ان‌یونیت (NUnit) است. جرارد مزاروش، با تکیه بر تجربه‌ی بالغ بر یک دهه‌ی خود در این حوزه، ۶۸ الگوی کاربردی را گردآوری کرده که به توسعه‌دهندگان کمک می‌کند تا آزمون‌هایی بنویسند که ساده‌تر، خواناتر و در طول‌مدت مقرون‌به‌صرفه‌تر باشند. ساختار کتاب به‌گونه‌ای طراحی شده که گویی سه کتاب را در یک جلد گرد هم آورده است: بخش نخست، یک آموزش مفصل درباره‌ی استراتژی و اصول آزمون خودکار است؛ بخش دوم، فهرستی از ۱۸ بوی بد (test smells) رایج را ارائه می‌دهد که به عیب‌یابی مشکلات کد آزمون کمک می‌کند؛ و بخش سوم، به‌تفصیل به تشریح هر یک از الگوها و نحوه‌ی بازسازی (refactoring) کد برای رفع بوهای بد می‌پردازد. ایده‌ی محوری کتاب بر این اصل استوار است که کد آزمون نیز مانند کد تولیدی، نیازمند توجه، دقت و نگهداری است. مزاروش با معرفی مفاهیمی مانند «چهار فاز آزمون خودکار» (شامل برپایی فیکسچر، اجرای سیستم تحت آزمون، راستی‌آزمایی نتیجه و پاک‌سازی فیکسچر) و تکنیک‌هایی مانند استفاده از اشیاء ساختگی (Mock Objects) و جای‌گذین‌ها (Test Stubs)، به خواننده نشان می‌دهد که چگونه می‌توان آزمون‌ها را از محیط اطراف خود مجزا کرده و پوشش و کارایی آن‌ها را افزایش داد. رویکرد مبتنی بر الگو (pattern-based) این کتاب، به خواننده امکان می‌دهد تا به‌جای استفاده از آزمون و خطا، از راه‌حل‌های آزمون‌شده برای مسائل تکراری استفاده کند و درک عمیق‌تری از «چرایی» و «چگونگی» هر تکنیک به دست آورد.

دربارهٔ نویسنده

نویسنده‌ی کتاب، جرارد مزاروش (Gerard Meszaros)، یکی از متخصصان برجسته در حوزه‌ی توسعه‌ی چابک (Agile) و آزمون خودکار نرم‌افزار است. او به‌عنوان دانشمند ارشد و مشاور ارشد در شرکت کلیراستریم کانسالتینگ (ClearStream Consulting) فعالیت می‌کند و بیش از یک دهه تجربه در زمینه‌ی فریم‌ورک‌های آزمون واحد و الگوهای اتوماسیون آزمون دارد. مزاروش علاوه بر تألیف این کتاب، در نگارش چندین کتاب دیگر نیز مشارکت داشته و به‌عنوان سخنران در کنفرانس‌های معتبر بین‌المللی حضور داشته است. تخصص اصلی او در زمینه‌ی بازسازی کد، طراحی برای آزمون‌پذیری و استراتژی‌های آزمون خودکار است که در این کتاب به‌خوبی به کار گرفته شده است.

چرا باید «الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)» را بخوانید؟

این کتاب با ارائه‌ی بینش‌های کلیدی و کاربردی، مزایای متعددی برای خواننده به ارمغان می‌آورد که در ادامه به برخی از مهم‌ترین آن‌ها اشاره می‌شود:
  • افزایش بازگشت سرمایه در توسعه نرم‌افزار: با یادگیری روش‌های بازسازی (refactoring) کد آزمون، هزینه‌های نگهداری آزمون‌ها را به‌طور قابل‌توجهی کاهش داده و از بروز مشکلات پرهزینه در آینده جلوگیری می‌کنید.
  • شناخت و رفع بوهای بد (Test Smells): کتاب یک کاتالوگ جامع از ۱۸ بوی بد رایج در کد آزمون ارائه می‌دهد که به شما کمک می‌کند تا مشکلات را تشخیص داده و بهترین راه‌حل را برای رفع آن‌ها بیابید.
  • دسترسی به ۶۸ الگوی اثبات‌شده: با استفاده از این الگوهای آزمون‌شده، می‌توانید به‌سرعت برای مسائل تکراری طراحی آزمون راه‌حل پیدا کنید و آزمون‌هایی بنویسید که ساده‌تر، خواناتر و قابل‌اعتمادتر هستند.
  • آشنایی با اصول و فلسفه‌ی آزمون خودکار: کتاب فراتر از ارائه‌ی الگوها رفته و به تشریح اصول و فلسفه‌ی حاکم بر آزمون خودکار می‌پردازد که به شما در انتخاب آگاهانه‌ی بهترین استراتژی کمک می‌کند.
  • قابلیت استفاده در فریم‌ورک‌های دیگر: هرچند این کتاب بر روی فریم‌ورک xUnit متمرکز است، اما الگوها و مفاهیم آن برای سایر چارچوب‌های آزمون مانند RSpec، JBehave و FitNesse نیز قابل تعمیم است.

این کتاب برای چه کسانی مناسب است؟

این کتاب منبعی ارزشمند برای طیف گسترده‌ای از توسعه‌دهندگان، مدیران و آزمون‌گرانی است که با هر فرایند توسعه‌ای (چابک یا سنتی) کار می‌کنند. چه از روش توسعه‌ی آزمون‌محور (TDD) استفاده کنید و چه آزمون‌ها را پس از نوشتن کد تولیدی بنویسید، مفاهیم این کتاب به شما در خلق آزمون‌هایی کارآمدتر و باکیفیت‌تر کمک خواهد کرد. این کتاب برای توسعه‌دهندگانی که به‌دنبال ارتقای سطح مهارت خود در نوشتن آزمون‌های واحد و یکپارچه هستند، و همچنین برای تیم‌هایی که با چالش‌های نگهداری کد آزمون دست‌وپنجه نرم می‌کنند، یک منبع ضروری و بی‌نظیر محسوب می‌شود.

سوالات متداول

آیا برای استفاده از این کتاب، دانش قبلی در مورد فریم‌ورک xUnit ضروری است؟

خیر، این کتاب با یک آموزش مفصل در بخش اول خود شروع می‌شود که مبانی و اصول کار با فریم‌ورک‌های xUnit را پوشش می‌دهد. حتی اگر تجربه‌ی کمی با این ابزارها داشته باشید، می‌توانید از محتوای کتاب بهره ببرید. همچنین الگوها و مفاهیم کتاب برای سایر ابزارهای آزمون نیز کاربرد دارند.

آیا کتاب فقط بر روی کدنویسی آزمون واحد (Unit Testing) تمرکز دارد؟

اگرچه محور اصلی کتاب بر روی آزمون واحد با استفاده از xUnit است، اما مباحث آن به‌طور گسترده‌ای برای آزمون‌های یکپارچه‌سازی (Integration Testing)، آزمون‌های عملکردی (Functional Testing) و حتی آزمون‌های مبتنی بر داده (Data-Driven Testing) نیز قابل تعمیم است. این کتاب به موضوعاتی مانند تعامل با پایگاه‌داده و مدیریت فیکسچرهای موقت و دائمی نیز می‌پردازد که فراتر از آزمون واحد صرف هستند.

آیا مثال‌های کتاب برای زبان برنامه‌نویسی خاصی نوشته شده است؟

مثال‌های کد این کتاب به‌گونه‌ای طراحی شده‌اند که در چندین زبان برنامه‌نویسی قابل‌درک باشند و به‌طور خاص به یک زبان وابسته نیستند. با این حال، با توجه به اینکه خانواده‌ی xUnit در زبان‌های مختلفی مانند جاوا، دات‌نت، پایتون و غیره پیاده‌سازی شده است، مفاهیم کتاب به‌راحتی برای هر کدام از این پلتفرم‌ها قابل تطبیق است.

XUnit Test Patterns uses the practice of patterns to share proven techniques for writing automated tests using the XUnit family (e.g., JUnit and NUnit) of test automation frameworks. When properly applied, these patterns result in tests that are easier to write, easier to understand, more robust and repeatable, easier to maintain, and ultimately more cost-effective. * Maximize software return on investment by learning how to refactor test code and reduce or prevent crippling test maintenance. * All patterns are introduced with a narrative section discussing the principles behind each one. * Includes a comprehensive glossary of testing and test automation terms.Software testing has received renewed attention with the widespread adoption of Extreme Programming and other agile methodologies. The under-appreciated practice of testing provides a timely and accurate measurement - a reality check - so that developers know whether any new action needs to be taken. And automated software testing ensures that once the software works, it is not accidentally broken during subsequent software development or maintenance activities. XUnit test patterns : refactoring test code 1 Contents 10 Visual Summary of the Pattern Language 20 Foreword 22 Preface 24 Acknowledgments 30 Introduction 32 Refactoring a Test 48 PART I. The Narratives 64 Chapter 1. A Brief Tour 66 About This Chapter 66 The Simplest Test Automation Strategy That Could Possibly Work 66 What鈥檚 Next? 71 Chapter 2. Test Smells 72 About This Chapter 72 An Introduction to Test Smells 72 A Catalog of Smells 75 What鈥檚 Next? 80 Chapter 3. Goals of Test Automation 82 About This Chapter 82 Why Test? 82 Goals of Test Automation 84 What鈥檚 Next? 92 Chapter 4. Philosophy of Test Automation 94 About This Chapter 94 Why Is Philosophy Important? 94 Some Philosophical Differences 95 When Philosophies Differ 100 My Philosophy 100 What鈥檚 Next? 100 Chapter 5. Principles of Test Automation 102 About This Chapter 102 The Principles 102 What鈥檚 Next? 111 Chapter 6. Test Automation Strategy 112 About This Chapter 112 What鈥檚 Strategic? 112 Which Kinds of Tests Should We Automate? 113 Which Tools Do We Use to Automate Which Tests? 116 Which Test Fixture Strategy Do We Use? 121 How Do We Ensure Testability? 128 What鈥檚 Next? 136 Chapter 7. xUnit Basics 138 About This Chapter 138 An Introduction to xUnit 138 Common Features 139 The Bare Minimum 139 Under the xUnit Covers 144 xUnit in the Procedural World 145 What鈥檚 Next? 146 Chapter 8. Transient Fixture Management 148 About This Chapter 148 Test Fixture Terminology 149 Building Fresh Fixtures 151 Tearing Down Transient Fresh Fixtures 156 What鈥檚 Next? 157 Chapter 9. Persistent Fixture Management 158 About This Chapter 158 Managing Persistent Fresh Fixtures 158 Managing Shared Fixtures 166 What鈥檚 Next? 169 Chapter 10. Result Verification 170 About This Chapter 170 Making Tests Self-Checking 170 State Verification 172 Verifying Behavior 175 Reducing Test Code Duplication 177 Avoiding Conditional Test Logic 182 Other Techniques 184 Where to Put Reusable Verification Logic? 185 What鈥檚 Next? 186 Chapter 11. Using Test Doubles 188 About This Chapter 188 What Are Indirect Inputs and Outputs? 188 Testing with Doubles 196 Other Uses of Test Doubles 211 Other Considerations 213 What鈥檚 Next? 214 Chapter 12. Organizing Our Tests 216 About This Chapter 216 Basic xUnit Mechanisms 216 Right-Sizing Test Methods 217 Test Methods and Testcase Classes 218 Test Naming Conventions 221 Organizing Test Suites 223 Test Code Reuse 225 Test File Organization 227 What鈥檚 Next? 228 Chapter 13. Testing with Databases 230 About This Chapter 230 Testing with Databases 230 Testing without Databases 232 Testing the Database 234 Testing with Databases (Again!) 236 What鈥檚 Next? 237 Chapter 14. A Roadmap to Effective Test Automation 238 About This Chapter 238 Test Automation Difficulty 238 Roadmap to Highly Maintainable Automated Tests 239 What鈥檚 Next? 244 PART II. The Test Smells 246 Chapter 15. Code Smells 248 Obscure Test 249 Conditional Test Logic 263 Hard-to-Test Code 272 Test Code Duplication 276 Test Logic in Production 280 Chapter 16. Behavior Smells 286 Assertion Roulette 287 Erratic Test 291 Fragile Test 302 Frequent Debugging 311 Manual Intervention 313 Slow Tests 316 Chapter 17. Project Smells 322 Buggy Tests 323 Developers Not Writing Tests 326 High Test Maintenance Cost 328 Production Bugs 331 PART III. The Patterns 338 Chapter 18. Test Strategy Patterns 340 Recorded Test 341 Scripted Test 348 Data-Driven Test 351 Test Automation Framework 361 Minimal Fixture 365 Standard Fixture 368 Fresh Fixture 374 Shared Fixture 380 Back Door Manipulation 390 Layer Test 400 Chapter 19. xUnit Basics Patterns 410 Test Method 411 Four-Phase Test 421 Assertion Method 425 Assertion Message 433 Testcase Class 436 Test Runner 440 Testcase Object 445 Test Suite Object 450 Test Discovery 456 Test Enumeration 462 Test Selection 466 Chapter 20. Fixture Setup Patterns 470 In-line Setup 471 Delegated Setup 474 Creation Method 478 Implicit Setup 487 Prebuilt Fixture 492 Lazy Setup 498 Suite Fixture Setup 504 Setup Decorator 510 Chained Tests 517 Chapter 21. Result Verification Patterns 524 State Verification 525 Behavior Verification 531 Custom Assertion 537 Delta Assertion 548 Guard Assertion 553 Unfinished Test Assertion 557 Chapter 22. Fixture Teardown Patterns 562 Garbage-Collected Teardown 563 Automated Teardown 566 In-line Teardown 572 Implicit Teardown 579 Chapter 23. Test Double Patterns 584 Test Double 585 Test Stub 592 Test Spy 601 Mock Object 607 Fake Object 614 Configurable Test Double 621 Hard-Coded Test Double 631 Test-Specific Subclass 642 Chapter 24. Test Organization Patterns 654 Named Test Suite 655 Test Utility Method 662 Parameterized Test 670 Testcase Class per Class 680 Testcase Class per Feature 687 Testcase Class per Fixture 694 Testcase Superclass 701 Test Helper 706 Chapter 25. Database Patterns 712 Database Sandbox 713 Stored Procedure Test 717 Table Truncation Teardown 724 Transaction Rollback Teardown 731 Chapter 26. Design-for-Testability Patterns 740 Dependency Injection 741 Dependency Lookup 749 Humble Object 758 Test Hook 772 Chapter 27. Value Patterns 776 Literal Value 777 Derived Value 781 Generated Value 786 Dummy Object 791 PART IV. Appendixes 796 Appendix A. Test Refactorings 798 Appendix B. xUnit Terminology 804 Appendix C. xUnit Family Members 810 Appendix D. Tools 816 Appendix E. Goals and Principles 820 Appendix F. Smells, Aliases, and Causes 824 Appendix G. Patterns, Aliases, and Variations 830 Glossary 848 A 848 B 850 C 852 D 854 E 856 F 858 G 861 H 862 I 862 L 865 M 865 N 867 O 867 P 868 R 870 S 871 T 874 U 879 V 880 References 882 Index 898 A 898 B 900 C 901 D 904 E 908 F 910 G 914 H 915 I 916 J 919 K 919 L 920 M 921 N 922 O 923 P 924 Q 927 R 927 S 929 T 935 U 944 V 945 W 945 X 945

Automated testing is a cornerstone of agile development. An effective testing strategy will deliver new functionality more aggressively, accelerate user feedback, and improve quality. However, for many developers, creating effective automated tests is a unique and unfamiliar challenge.

xUnit Test Patterns is the definitive guide to writing automated tests using xUnit, the most popular unit testing framework in use today. Agile coach and test automation expert Gerard Meszaros describes 68 proven patterns for making tests easier to write, understand, and maintain. He then shows you how to make them more robust and repeatable--and far more cost-effective.

Loaded with information, this book feels like three books in one. The first part is a detailed tutorial on test automation that covers everything from test strategy to in-depth test coding. The second part, a catalog of 18 frequently encountered "test smells," provides trouble-shooting guidelines to help you determine the root cause of problems and the most applicable patterns. The third part contains detailed descriptions of each pattern, including refactoring instructions illustrated by extensive code samples in multiple programming languages.

Topics covered include

  • Writing better tests--and writing them faster
  • The four phases of automated tests: fixture setup, exercising the system under test, result verification, and fixture teardown
  • Improving test coverage by isolating software from its environment using Test Stubs and Mock Objects
  • Designing software for greater testability
  • Using test "smells" (including code smells, behavior smells, and project smells) to spot problems and know when and how to eliminate them
  • Refactoring tests for greater simplicity, robustness, and execution speed

This book will benefit developers, managers, and testers working with any agile or conventional development process, whether doing test-driven development or writing the tests last. While the patterns and smells are especially applicable to all members of the xUnit family, they also apply to next-generation behavior-driven development frameworks such as RSpec and JBehave and to other kinds of test automation tools, including recorded test tools and data-driven test tools such as Fit and FitNesse.

Visual Summary of the Pattern Language
Foreword

Preface

Acknowledgments

Introduction

Refactoring a Test

PART I: The Narratives Chapter 1 A Brief Tour Chapter 2 Test Smells Chapter 3 Goals of Test Automation Chapter 4 Philosophy of Test Automation Chapter 5 Principles of Test Automation Chapter 6 Test Automation Strategy Chapter 7 xUnit Basics Chapter 8 Transient Fixture Management Chapter 9 Persistent Fixture Management Chapter 10 Result Verification Chapter 11 Using Test Doubles Chapter 12 Organizing Our Tests Chapter 13 Testing with Databases Chapter 14 A Roadmap to Effective Test Automation PART II: The Test Smells Chapter 15 Code Smells Chapter 16 Behavior Smells Chapter 17 Project Smells PART III: The Patterns Chapter 18 Test Strategy Patterns Chapter 19 xUnit Basics Patterns Chapter 20 Fixture Setup Patterns Chapter 21 Result Verification Patterns Chapter 22 Fixture Teardown Patterns Chapter 23 Test Double Patterns Chapter 24 Test Organization Patterns Chapter 25 Database Patterns Chapter 26 Design-for-Testability Patterns Chapter 27 Value Patterns PART IV: Appendixes Appendix A Test Refactorings Appendix B xUnit Terminology Appendix C xUnit Family Members Appendix D Tools Appendix E Goals and Principles Appendix F Smells, Aliases, and Causes Appendix G Patterns, Aliases, and Variations
Glossary
References

Index

Automated testing is a cornerstone of agile development. An effective testing strategy will deliver new functionality more aggressively, accelerate user feedback, and improve quality. However, for many developers, creating effective automated tests is a unique and unfamiliar challenge. xUnit Test Patterns is the definitive guide to writing automated tests using xUnit, the most popular unit testing framework in use today. Agile coach and test automation expert Gerard Meszaros describes 68 proven patterns for making tests easier to write, understand, and maintain. He then shows you how to make them more robust and repeatable--and far more cost-effective. Loaded with information, this book feels like three books in one. The first part is a detailed tutorial on test automation that covers everything from test strategy to in-depth test coding. The second part, a catalog of 18 frequently encountered "test smells," provides trouble-shooting guidelines to help you determine the root cause of problems and the most applicable patterns. The third part contains detailed descriptions of each pattern, including refactoring instructions illustrated by extensive code samples in multiple programming languages. Topics covered include Writing better tests--and writing them faster The four phases of automated tests: fixture setup, exercising the system under test, result verification, and fixture teardown Improving test coverage by isolating software from its environment using Test Stubs and Mock Objects Designing software for greater testability Using test "smells" (including code smells, behavior smells, and project smells) to spot problems and know when and how to eliminate them Refactoring tests for greater simplicity, robustness, and execution speed This book will benefit developers, managers, and testers working with any agile or conventional development process, whether doing test-driven development or writing the tests last. While the patterns and smells are especially applicable to all members of the xUnit family, they also apply to next-generation behavior-driven development frameworks such as RSpec and JBehave and to other kinds of test automation tools, including recorded test tools and data-driven test tools such as Fit and FitNesse. Visual Summary of the Pattern Language Foreword Preface Acknowledgments Introduction Refactoring a Test PART I: The Narratives Chapter 1 A Brief Tour Chapter 2 Test Smells Chapter 3 Goals of Test Automation Chapter 4 Philosophy of Test Automation Chapter 5 Principles of Test Automation Chapter 6 Test Automation Strategy Chapter 7 xUnit Basics Chapter 8 Transient Fixture Management Chapter 9 Persistent Fixture Management Chapter 10 Result Verification Chapter 11 Using Test Doubles Chapter 12 Organizing Our Tests Chapter 13 Testing with Databases Chapter 14 A Roadmap to Effective Test Automation PART II: The Test Smells Chapter 15 Code Smells Chapter 16 Behavior Smells Chapter 17 Project Smells PART III: The Patterns Chapter 18 Test Strategy Patterns Chapter 19 xUnit Basics Patterns Chapter 20 Fixture Setup Patterns Chapter 21 Result Verification Patterns Chapter 22 Fixture Teardown Patterns Chapter 23 Test Double Patterns Chapter 24 Test Organization Patterns Chapter 25 Database Patterns Chapter 26 Design-for-Testability Patterns Chapter 27 Value Patterns PART IV: Appendixes Appendix A Test Refactorings Appendix B xUnit Terminology Appendix C xUnit Family Members Appendix D Tools Appendix E Goals and Principles Appendix F Smells, Aliases, and Causes Appendix G Patterns, Aliases, and Variations Glossary References Index " A guide to writing automated tests for XUnit test automation frameworks. It introduces proven patterns for making tests easier to write, understand, and maintain. It includes topics such as: Writing better tests - and writing them faster; Software testing phases: fixture set up, exercise SUT, result verification, and fixture tear down; and more. This text improves software return on investment by teaching the reader how to refactor test code and reduce of prevent crippling test maintenance. A comprehensive glossary of testing and test automation terms are included
دانلود کتاب الگوهای آزمون xUnit: بازسازی کد آزمون (مجموعهٔ امضای ادیسون-وِسلی)