Beställningsvara. Skickas inom 7-10 vardagar. Fri frakt för medlemmar vid köp för minst 249 kr.
Hands-on guidance to creating great test-driven development practice Test-driven development (TDD) practice helps developers recognize a well-designed application, and encourages writing a test before writing the functionality that needs to be implemented. This hands-on guide provides invaluable insight for creating successful test-driven development processes. With source code and examples featured in both C# and .NET, the book walks you through the TDD methodology and shows how it is applied to a real-world application. You’ll witness the application built from scratch and details each step that is involved in the development, as well as any problems that were encountered and the solutions that were applied. Clarifies the motivation behind test-driven development (TDD), what it is, and how it worksReviews the various steps involved in developing an application and the testing that is involved prior to implementing the functionalityDiscusses unit testing and refactoringProfessional Test-Driven Development with C# shows you how to create great TDD processes right away.
James Bender is Vice President of Technology for Improving Enterprises. He is a Microsoft MVP, working on everything from small, single-user applications to Enterprise-scale, multi-user systems. Jeff McWherter is a Partner and Director of Development at Gravity Works Design and Development. In 2010 Jeff was awarded with the Microsoft MVP for the third consecutive year.
INTRODUCTION xxvPART I: GETTING STARTEDCHAPTER 1: THE ROAD TO TEST-DRIVEN DEVELOPMENT 3The Classical Approach to Software Development 4A Brief History of Software Engineering 4From Waterfall to Iterative and Incremental 5A Quick Introduction to Agile Methodologies 6A Brief History of Agile Methodologies 6The Principles and Practices of Test-Driven Development 7The Concepts Behind TDD 8TDD as a Design Methodology 8TDD as a Development Practice 8The Benefi ts of TDD 9A Quick Example of the TDD Approach 10Summary 17CHAPTER 2: AN INTRODUCTION TO UNIT TESTING 19What Is a Unit Test? 19Unit Test Definition 20What Is Not a Unit Test? 20Other Types of Tests 22A Brief Look at NUnit 24What Is a Unit Test Framework? 24The Basics of NUnit 25Decoupling with Mock Objects 28Why Mocking Is Important 28Dummy, Fake, Stub, and Mock 29Best and Worst Practices 35A Brief Look at Moq 36What Does a Mocking Framework Do? 36A Bit About Moq 36Moq Basics 36Summary 40CHAPTER 3: A QUICK REVIEW OF REFACTORING 41Why Refactor? 42A Project’s Lifecycle 42Maintainability 43Code Metrics 43Clean Code Principles 45OOP Principles 45Encapsulation 45Inheritance 46Polymorphism 48The SOLID Principles 49The Single Responsibility Principle 50The Open/Close Principle 50The Liskov Substitution Principle 51The Interface Segregation Principle 51The Dependency Inversion Principle 52Code Smells 52What Is a Code Smell? 52Duplicate Code and Similar Classes 53Big Classes and Big Methods 54Comments 55Bad Names 56Feature Envy 57Too Much If/Switch 58Try/Catch Bloat 59Typical Refactoring 60Extract Classes or Interfaces 60Extract Methods 62Rename Variables, Fields, Methods, and Classes 66Encapsulate Fields 67Replace Conditional with Polymorphism 68Allow Type Inference 71Summary 71CHAPTER 4: TEST-DRIVEN DEVELOPMENT: LET THE TESTS BE YOUR GUIDE 73It Starts with the Test 74Red, Green, Refactor 76The Three Phases of TDD 77The Red Phase 77The Green Phase 78The Refactoring Phase 79Starting Again 79A Refactoring Example 79The First Feature 80Making the First Test Pass 83The Second Feature 83Refactoring the Unit Tests 85The Third Feature 87Refactoring the Business Code 88Correcting Refactoring Defects 91The Fourth Feature 93Summary 94CHAPTER 5: MOCKING EXTERNAL RESOURCES 97The Dependency Injection Pattern 98Working with a Dependency Injection Framework 99Abstracting the Data Access Layer 108Moving the Database Concerns Out of the Business Code 108Isolating Data with the Repository Pattern 108Injecting the Repository 109Mocking the Repository 112Summary 113PART II: PUTTING BASICS INTO ACTIONCHAPTER 6: STARTING THE SAMPLE APPLICATION 117Defi ning the Project 118Developing the Project Overview 118Defi ning the Target Environment 119Choosing the Application Technology 120Defi ning the User Stories 120Collecting the Stories 120Defi ning the Product Backlog 122The Agile Development Process 123Estimating 124Working in Iterations 124Communication Within Your Team 126Iteration Zero: Your First Iteration 127Testing in Iteration Zero 127Ending an Iteration 128Creating the Project 129Choosing the Frameworks 129Defi ning the Project Structure 131Organizing Project Folders 131Creating the Visual Studio Solution 132Summary 134CHAPTER 7: IMPLEMENTING THE FIRST USER STORY 137The First Test 138Choosing the First Test 138Naming the Test 139Writing the Test 140Implementing the Functionality 148Writing the Simplest Thing That Could Possibly Work 148Running the Passing Test 157Writing the Next Test 158Improving the Code by Refactoring 165Triangulation of Tests 166Summary 166CHAPTER 8: INTEGRATION TESTING 169Integrate Early; Integrate Often 170Writing Integration Tests 171How to Manage the Database 171How to Write Integration Tests 172Reviewing the ItemTypeRepository 173Adding Ninject for Dependency Injection 174Creating the Fluent NHibernate Confi guration 177Creating the Fluent NHibernate Mapping 179Creating the Integration Test 183End-to-End Integration Tests 191Keeping Various Types of Tests Apart 191When and How to Run Integration Tests 191Summary 192PART III: TDD SCENARIOSCHAPTER 9: TDD ON THE WEB 197ASP.NET Web Forms 197Web Form Organization 198ASPX Files 198Code-Behind Files 198Implementing Test-Driven Development with MVP and Web Forms 199Working with the ASP.NET MVC 210MVC 101 211Microsoft ASP.NET MVC 3.0 212Creating an ASP.NET MVC Project 212Creating Your First Test 213Making Your First Test Pass 215Creating Your First View 216Gluing Everything Together 217Using the MVC Contrib Project 220ASP.NET MVC Summarized 220Working with JavaScript 220JavaScript Testing Frameworks 221Summary 226CHAPTER 10: TESTING WINDOWS COMMUNICATION FOUNDATION SERVICES 227WCF Services in Your Application 228Services Are Code Too 228Testing WCF Services 228Refactoring for Testability 229Introducing Dependency Injection to Your Service 231Writing the Test 236Stubbing the Dependencies 239Verifying the Results 243Trouble Spots to Watch 244Summary 244CHAPTER 11: TESTING WPF AND SILVERLIGHT APPLICATIONS 245The Problem with Testing the User Interface 246The MVVM Pattern 246How MVVM Makes WPF/Silverlight Applications Testable 248Bringing It All Together 261Summary 263PART IV: REQUIREMENTS AND TOOLSCHAPTER 12: DEALING WITH DEFECTS AND NEW REQUIREMENTS 267Handling Change 268Change Happens 268Adding New Features 268Addressing Defects 269Starting with a Test 270Changing the Code 272Keeping the Tests Passing 276Summary 276CHAPTER 13: THE GREAT TOOL DEBATE 279Test Runners 279TestDriven.NET 280Developer Express Test Runner 280Gallio 281Unit Testing Frameworks 282MSTest 282MbUnit 283xUnit 284Mocking Frameworks 285Rhino Mocks 285Type Mock 287Dependency Injection Frameworks 289Structure Map 289Unity 291Windsor 293Autofac 294Miscellaneous Useful Tools 295nCover 295PEX 295How to Introduce TDD to Your Team 296Working in Environments That Are Resistant to Change 297Working in Environments That Are Accepting of Change 297Summary 297CHAPTER 14: CONCLUSIONS 299What You Have Learned 299You Are the Client of Your Code 300Find the Solutions Step by Step 300Use the Debugger as a Surgical Instrument 300TDD Best Practices 301Use Signifi cant Names 301Write at Least One Test for One Unit of Functionality 301Keep Your Mocks Simple 302The Benefi ts of TDD 302How to Introduce TDD in Your Team 303Summary 304APPENDIX: TDD KATAS 307Working with TDD Katas 307Share Your Work 308OSIM User Stories 308INDEX 311