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 works Reviews the various steps involved in developing an application and the testing that is involved prior to implementing the functionality Discusses unit testing and refactoring Professional Test-Driven Development with C# shows you how to create great TDD processes right away.
Author(s): James Bender; Jeff McWherter
Publisher: Wrox Press
Year: 2011
Language: English
Pages: 360
Professional Test-Driven Development with C#: Developing Real World Applications with TDD
Contents
Introduction
Part I: Getting Started
Chapter 1: The Road to Test-Driven Development
The Classical Approach to Software Development
A Brief History of Software Engineering
From Waterfall to Iterative and Incremental
A Quick Introduction to Agile Methodologies
A Brief History of Agile Methodologies
The Principles and Practices of Test-Driven Development
The Concepts Behind TDD
TDD as a Design Methodology
TDD as a Development Practice
The Benefits of TDD
A Quick Example of the TDD Approach
Summary
Chapter 2: An Introduction to Unit Testing
What Is a Unit Test?
Unit Test Definition
What Is Not a Unit Test?
Other Types of Tests
A Brief Look at NUnit
What Is a Unit Test Framework?
The Basics of NUnit
Decoupling with Mock Objects
Why Mocking Is Important
Dummy, Fake, Stub, and Mock
Best and Worst Practices
A Brief Look at Moq
What Does a Mocking Framework Do?
A Bit About Moq
Moq Basics
Summary
Chapter 3: A Quick Review of Refactoring
Why Refactor?
A Project's Lifecycle
Maintainability
Code Metrics
Clean Code Principles
OOP Principles
Encapsulation
Inheritance
Polymorphism
The SOLID Principles
The Single Responsibility Principle
The Open/Close Principle
The Liskov Substitution Principle
The Interface Segregation Principle
The Dependency Inversion Principle
Code Smells
What Is a Code Smell?
Duplicate Code and Similar Classes
Big Classes and Big Methods
Comments
Bad Names
Feature Envy
Too Much If/Switch
Try/Catch Bloat
Typical Refactoring
Extract Classes or Interfaces
Extract Methods
Rename Variables, Fields, Methods, and Classes
Encapsulate Fields
Replace Conditional with Polymorphism
Allow Type Inference
Summary
Chapter 4: Test-Driven Development: Let the Tests Be Your Guide
It Starts with the Test
Red, Green, Refactor
The Three Phases of TDD
The Red Phase
The Green Phase
The Refactoring Phase
Starting Again
A Refactoring Example
The First Feature
Making the First Test Pass
The Second Feature
Refactoring the Unit Tests
The Third Feature
Refactoring the Business Code
Correcting Refactoring Defects
The Fourth Feature
Summary
Chapter 5: Mocking External Resources
The Dependency Injection Pattern
Working with a Dependency Injection Framework
Abstracting the Data Access Layer
Moving the Database Concerns Out of the Business Code
Isolating Data with the Repository Pattern
Injecting the Repository
Mocking the Repository
Summary
Part II: Putting Basics into Action
Chapter 6: Starting the Sample Application
Defining the Project
Developing the Project Overview
Defining the Target Environment
Choosing the Application Technology
Defining the User Stories
Collecting the Stories
Defining the Product Backlog
The Agile Development Process
Estimating
Working in Iterations
Communication Within Your Team
Iteration Zero: Your First Iteration
Testing in Iteration Zero
Ending an Iteration
Creating the Project
Choosing the Frameworks
Defining the Project Structure
Organizing Project Folders
Creating the Visual Studio Solution
Summary
Chapter 7: Implementing the First User Story
The First Test
Choosing the First Test
Naming the Test
Writing the Test
Implementing the Functionality
Writing the Simplest Thing That Could Possibly Work
Running the Passing Test
Writing the Next Test
Improving the Code by Refactoring
Triangulation of Tests
Summary
Chapter 8: Integration Testing
Integrate Early; Integrate Often
Writing Integration Tests
How to Manage the Database
How to Write Integration Tests
Reviewing the ItemTypeRepository
Adding Ninject for Dependency Injection
Creating the Fluent NHibernate Configuration
Creating the Fluent NHibernate Mapping
Creating the Integration Test
End-to-End Integration Tests
Keeping Various Types of Tests Apart
When and How to Run Integration Tests
Summary
Part III: TDD Scenarios
Chapter 9: TDD on The Web
ASP.NET Web Forms
Web Form Organization
ASPX Files
Code-Behind Files
Implementing Test-Driven Development with MVP and Web Forms
Working with the ASP.NET MVC
MVC 101
Microsoft ASP.NET MVC 3.0
Creating an ASP.NET MVC Project
Creating Your First Test
Making Your First Test Pass
Creating Your First View
Gluing Everything Together
Using the MVC Contrib Project
ASP.NET MVC Summarized
Working with JavaScript
JavaScript Testing Frameworks
Summary
Chapter 10: Testing Windows Communication Foundation Services
WCF Services in Your Application
Services Are Code Too
Testing WCF Services
Refactoring for Testability
Introducing Dependency Injection to Your Service
Writing the Test
Stubbing the Dependencies
Verifying the Results
Trouble Spots to Watch
Summary
Chapter 11: Testing WPF and Silverlight Applications
The Problem with Testing the User Interface
The MVVM Pattern
How MVVM Makes WPF/Silverlight Applications Testable
Bringing It All Together
Summary
Part IV: Requirements and Tools
Chapter 12: Dealing with Defects and New Requirements
Handling Change
Change Happens
Adding New Features
Addressing Defects
Starting with a Test
Changing the Code
Keeping the Tests Passing
Summary
Chapter 13: The Great Tool Debate
Test Runners
TestDriven.NET
Developer Express Test Runner
Gallio
Unit Testing Frameworks
MSTest
MbUnit
xUnit
Mocking Frameworks
Rhino Mocks
Type Mock
Dependency Injection Frameworks
Structure Map
Unity
Windsor
Autofac
Miscellaneous Useful Tools
nCover
PEX
How to Introduce TDD to Your Team
Working in Environments That Are Resistant to Change
Working in Environments That Are Accepting of Change
Summary
Chapter 14: Conclusions
What You Have Learned
You Are the Client of Your Code
Find the Solutions Step by Step
Use the Debugger as a Surgical Instrument
TDD Best Practices
Use Significant Names
Write at Least One Test for One Unit of Functionality
Keep Your Mocks Simple
The Benefits of TDD
How to Introduce TDD in Your Team
Summary
Appendix: TDD Katas
Working with TDD Katas
Share Your Work
OSIM User Stories
Index