Details

Professional Test Driven Development with C#


Professional Test Driven Development with C#

Developing Real World Applications with TDD
1. Aufl.

von: James Bender, Jeff McWherter

28,99 €

Verlag: Wiley
Format: EPUB
Veröffentl.: 09.05.2011
ISBN/EAN: 9781118102114
Sprache: englisch
Anzahl Seiten: 368

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<b>Hands-on guidance to creating great test-driven development practice</b> <p>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.</p> <ul> <li>Clarifies the motivation behind test-driven development (TDD), what it is, and how it works</li> <li>Reviews the various steps involved in developing an application and the testing that is involved prior to implementing the functionality</li> <li>Discusses unit testing and refactoring</li> </ul> <p><i>Professional Test-Driven Development with C#</i> shows you how to create great TDD processes right away.</p>
<p>INTRODUCTION xxv</p> <p><b>PART I: GETTING STARTED</b></p> <p><b>CHAPTER 1: THE ROAD TO TEST-DRIVEN DEVELOPMENT 3</b></p> <p>The Classical Approach to Software Development 4</p> <p>A Brief History of Software Engineering 4</p> <p>From Waterfall to Iterative and Incremental 5</p> <p>A Quick Introduction to Agile Methodologies 6</p> <p>A Brief History of Agile Methodologies 6</p> <p>The Principles and Practices of Test-Driven Development 7</p> <p>The Concepts Behind TDD 8</p> <p>TDD as a Design Methodology 8</p> <p>TDD as a Development Practice 8</p> <p>The Benefi ts of TDD 9</p> <p>A Quick Example of the TDD Approach 10</p> <p>Summary 17</p> <p><b>CHAPTER 2: AN INTRODUCTION TO UNIT TESTING 19</b></p> <p>What Is a Unit Test? 19</p> <p>Unit Test Definition 20</p> <p>What Is Not a Unit Test? 20</p> <p>Other Types of Tests 22</p> <p>A Brief Look at NUnit 24</p> <p>What Is a Unit Test Framework? 24</p> <p>The Basics of NUnit 25</p> <p>Decoupling with Mock Objects 28</p> <p>Why Mocking Is Important 28</p> <p>Dummy, Fake, Stub, and Mock 29</p> <p>Best and Worst Practices 35</p> <p>A Brief Look at Moq 36</p> <p>What Does a Mocking Framework Do? 36</p> <p>A Bit About Moq 36</p> <p>Moq Basics 36</p> <p>Summary 40</p> <p><b>CHAPTER 3: A QUICK REVIEW OF REFACTORING 41</b></p> <p>Why Refactor? 42</p> <p>A Project’s Lifecycle 42</p> <p>Maintainability 43</p> <p>Code Metrics 43</p> <p>Clean Code Principles 45</p> <p>OOP Principles 45</p> <p>Encapsulation 45</p> <p>Inheritance 46</p> <p>Polymorphism 48</p> <p>The SOLID Principles 49</p> <p>The Single Responsibility Principle 50</p> <p>The Open/Close Principle 50</p> <p>The Liskov Substitution Principle 51</p> <p>The Interface Segregation Principle 51</p> <p>The Dependency Inversion Principle 52</p> <p>Code Smells 52</p> <p>What Is a Code Smell? 52</p> <p>Duplicate Code and Similar Classes 53</p> <p>Big Classes and Big Methods 54</p> <p>Comments 55</p> <p>Bad Names 56</p> <p>Feature Envy 57</p> <p>Too Much If/Switch 58</p> <p>Try/Catch Bloat 59</p> <p>Typical Refactoring 60</p> <p>Extract Classes or Interfaces 60</p> <p>Extract Methods 62</p> <p>Rename Variables, Fields, Methods, and Classes 66</p> <p>Encapsulate Fields 67</p> <p>Replace Conditional with Polymorphism 68</p> <p>Allow Type Inference 71</p> <p>Summary 71</p> <p><b>CHAPTER 4: TEST-DRIVEN DEVELOPMENT: LET THE TESTS BE YOUR GUIDE 73</b></p> <p>It Starts with the Test 74</p> <p>Red, Green, Refactor 76</p> <p>The Three Phases of TDD 77</p> <p>The Red Phase 77</p> <p>The Green Phase 78</p> <p>The Refactoring Phase 79</p> <p>Starting Again 79</p> <p>A Refactoring Example 79</p> <p>The First Feature 80</p> <p>Making the First Test Pass 83</p> <p>The Second Feature 83</p> <p>Refactoring the Unit Tests 85</p> <p>The Third Feature 87</p> <p>Refactoring the Business Code 88</p> <p>Correcting Refactoring Defects 91</p> <p>The Fourth Feature 93</p> <p>Summary 94</p> <p><b>CHAPTER 5: MOCKING EXTERNAL RESOURCES 97</b></p> <p>The Dependency Injection Pattern 98</p> <p>Working with a Dependency Injection Framework 99</p> <p>Abstracting the Data Access Layer 108</p> <p>Moving the Database Concerns Out of the Business Code 108</p> <p>Isolating Data with the Repository Pattern 108</p> <p>Injecting the Repository 109</p> <p>Mocking the Repository 112</p> <p>Summary 113</p> <p><b>PART II: PUTTING BASICS INTO ACTION</b></p> <p><b>CHAPTER 6: STARTING THE SAMPLE APPLICATION 117</b></p> <p>Defi ning the Project 118</p> <p>Developing the Project Overview 118</p> <p>Defi ning the Target Environment 119</p> <p>Choosing the Application Technology 120</p> <p>Defi ning the User Stories 120</p> <p>Collecting the Stories 120</p> <p>Defi ning the Product Backlog 122</p> <p>The Agile Development Process 123</p> <p>Estimating 124</p> <p>Working in Iterations 124</p> <p>Communication Within Your Team 126</p> <p>Iteration Zero: Your First Iteration 127</p> <p>Testing in Iteration Zero 127</p> <p>Ending an Iteration 128</p> <p>Creating the Project 129</p> <p>Choosing the Frameworks 129</p> <p>Defi ning the Project Structure 131</p> <p>Organizing Project Folders 131</p> <p>Creating the Visual Studio Solution 132</p> <p>Summary 134</p> <p><b>CHAPTER 7: IMPLEMENTING THE FIRST USER STORY 137</b></p> <p>The First Test 138</p> <p>Choosing the First Test 138</p> <p>Naming the Test 139</p> <p>Writing the Test 140</p> <p>Implementing the Functionality 148</p> <p>Writing the Simplest Thing That Could Possibly Work 148</p> <p>Running the Passing Test 157</p> <p>Writing the Next Test 158</p> <p>Improving the Code by Refactoring 165</p> <p>Triangulation of Tests 166</p> <p>Summary 166</p> <p><b>CHAPTER 8: INTEGRATION TESTING 169</b></p> <p>Integrate Early; Integrate Often 170</p> <p>Writing Integration Tests 171</p> <p>How to Manage the Database 171</p> <p>How to Write Integration Tests 172</p> <p>Reviewing the ItemTypeRepository 173</p> <p>Adding Ninject for Dependency Injection 174</p> <p>Creating the Fluent NHibernate Confi guration 177</p> <p>Creating the Fluent NHibernate Mapping 179</p> <p>Creating the Integration Test 183</p> <p>End-to-End Integration Tests 191</p> <p>Keeping Various Types of Tests Apart 191</p> <p>When and How to Run Integration Tests 191</p> <p>Summary 192</p> <p><b>PART III: TDD SCENARIOS</b></p> <p><b>CHAPTER 9: TDD ON THE WEB 197</b></p> <p>ASP.NET Web Forms 197</p> <p>Web Form Organization 198</p> <p>ASPX Files 198</p> <p>Code-Behind Files 198</p> <p>Implementing Test-Driven Development with MVP and Web Forms 199</p> <p>Working with the ASP.NET MVC 210</p> <p>MVC 101 211</p> <p>Microsoft ASP.NET MVC 3.0 212</p> <p>Creating an ASP.NET MVC Project 212</p> <p>Creating Your First Test 213</p> <p>Making Your First Test Pass 215</p> <p>Creating Your First View 216</p> <p>Gluing Everything Together 217</p> <p>Using the MVC Contrib Project 220</p> <p>ASP.NET MVC Summarized 220</p> <p>Working with JavaScript 220</p> <p>JavaScript Testing Frameworks 221</p> <p>Summary 226</p> <p><b>CHAPTER 10: TESTING WINDOWS COMMUNICATION FOUNDATION SERVICES 227</b></p> <p>WCF Services in Your Application 228</p> <p>Services Are Code Too 228</p> <p>Testing WCF Services 228</p> <p>Refactoring for Testability 229</p> <p>Introducing Dependency Injection to Your Service 231</p> <p>Writing the Test 236</p> <p>Stubbing the Dependencies 239</p> <p>Verifying the Results 243</p> <p>Trouble Spots to Watch 244</p> <p>Summary 244</p> <p><b>CHAPTER 11: TESTING WPF AND SILVERLIGHT APPLICATIONS 245</b></p> <p>The Problem with Testing the User Interface 246</p> <p>The MVVM Pattern 246</p> <p>How MVVM Makes WPF/Silverlight Applications Testable 248</p> <p>Bringing It All Together 261</p> <p>Summary 263</p> <p><b>PART IV: REQUIREMENTS AND TOOLS</b></p> <p><b>CHAPTER 12: DEALING WITH DEFECTS AND NEW REQUIREMENTS 267</b></p> <p>Handling Change 268</p> <p>Change Happens 268</p> <p>Adding New Features 268</p> <p>Addressing Defects 269</p> <p>Starting with a Test 270</p> <p>Changing the Code 272</p> <p>Keeping the Tests Passing 276</p> <p>Summary 276</p> <p><b>CHAPTER 13: THE GREAT TOOL DEBATE 279</b></p> <p>Test Runners 279</p> <p>TestDriven.NET 280</p> <p>Developer Express Test Runner 280</p> <p>Gallio 281</p> <p>Unit Testing Frameworks 282</p> <p>MSTest 282</p> <p>MbUnit 283</p> <p>xUnit 284</p> <p>Mocking Frameworks 285</p> <p>Rhino Mocks 285</p> <p>Type Mock 287</p> <p>Dependency Injection Frameworks 289</p> <p>Structure Map 289</p> <p>Unity 291</p> <p>Windsor 293</p> <p>Autofac 294</p> <p>Miscellaneous Useful Tools 295</p> <p>nCover 295</p> <p>PEX 295</p> <p>How to Introduce TDD to Your Team 296</p> <p>Working in Environments That Are Resistant to Change 297</p> <p>Working in Environments That Are Accepting of Change 297</p> <p>Summary 297</p> <p><b>CHAPTER 14: CONCLUSIONS 299</b></p> <p>What You Have Learned 299</p> <p>You Are the Client of Your Code 300</p> <p>Find the Solutions Step by Step 300</p> <p>Use the Debugger as a Surgical Instrument 300</p> <p>TDD Best Practices 301</p> <p>Use Signifi cant Names 301</p> <p>Write at Least One Test for One Unit of Functionality 301</p> <p>Keep Your Mocks Simple 302</p> <p>The Benefi ts of TDD 302</p> <p>How to Introduce TDD in Your Team 303</p> <p>Summary 304</p> <p>APPENDIX: TDD KATAS 307</p> <p>Working with TDD Katas 307</p> <p>Share Your Work 308</p> <p>OSIM User Stories 308</p> <p>INDEX 311</p>
<b>James Bender</b> 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. <p><b>Jeff McWherter</b> 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.</p>
<b>Start working with test driven development processes to build better applications</b> <p>If you want to write robust software that is simple to implement and maintain, you need to use Test Driven Development (TDD). This hands-on guide shows you how, providing invaluable insight for creating effective TDD processes. With the help of source code and examples featured in C#, the authors walk you through the TDD methodology and show you how to apply it to a real-world application. You'll explore the application as it's built from scratch and follow each step involved in development, including problems that arise and the solutions to apply. Within no time, you'll be designing your own successful TDD processes.</p> <p><b><i>Professional Test Driven Development with C#</i>:</b></p> <ul> <li> <p>Describes common software problems and provides refactoring practices that resolve them</p> </li> <li> <p>Shows patterns that can be used to test WPF and Silverlight applications</p> </li> <li> <p>Helps you ensure that when a defect is fixed it stays fixed without causing unexpected side effects</p> </li> <li> <p>Shows how to structure your MVC application for testability</p> </li> <li> <p>Shares the easy steps that can be taken to test WCF services</p> </li> <li> <p>Explains how to run integration tests to ensure that everything works as planned</p> </li> <li> <p>Uncovers best practices for writing good tests that are readable and maintainable</p> </li> </ul> <p><b>Wrox Professional guides</b> are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.</p> <p><b>wrox.com</b></p> <p><b>Programmer Forums</b><br /> Join our Programmer to Programmer forums to ask and answer programming questions about this book, join discussions on the hottest topics in the industry, and connect with fellow programmers from around the world.</p> <p><b>Code Downloads</b><br /> Take advantage of free code samples from this book, as well as code samples from hundreds of other books, all ready to use.</p> <p><b>Read More</b><br /> Find articles, ebooks, sample chapters, and tables of contents for hundreds of books, and more reference resources on programming topics that matter to you.</p>

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €