售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright and Credits
Practical Test-Driven Development using C# 7
Packt Upsell
Why subscribe?
PacktPub.com
Foreword
Contributors
About the authors
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Why TDD is Important
First, a little background
John's story on TDD
Clayton's story on TDD
So, what is TDD?
An approach to TDD
An alternative approach
The process
Red, green, and refactor
Coder's block
Why should we care?
Arguments against TDD
Testing takes time
Testing is expensive
Testing is difficult
We don't know how
Arguments in favor of TDD
Reduces the effort of manual testing
Reduces bug count
Ensures some level of correctness
Removes the fear of refactoring
A better architecture
Faster development
Different types of test
Unit tests
Acceptance tests
Integration tests
End to end tests
Quantity of each test type
Parts of a unit test
Arrange
Act
Assert
Requirements
Why are they important?
User stories
Role
Request
Reason
Gherkin
Givens
When
Then
Our first tests in C#
Growing the application with tests
Our first tests in JavaScript
Why does it matter?
Summary
Setting Up the .NET Test Environment
Installing the .NET Core SDK
Getting set up with VS Code
Downloading the IDE
Installing the VS Code
Adding extensions
Creating a project in VS Code
Setting up Visual Studio Community
Downloading Visual Studio Community
Installing Visual Studio Community
Switching to xUnit
Code katas
FizzBuzz
Creating the test project
The Given3ThenFizz test
The Given5ThenBuzz test
The Given15ThenFizzBuzz test
The Given1Then1 test
Theories
Solution to the FizzBuzz Problem
What is Speaker Meet?
Web API project
Listing Speakers (API)
Requirements
A new test file
Summary
Setting Up a JavaScript Environment
Node.js
What is Node?
Why do we need Node?
Installing Node
Linux
Mac OSX
Windows
NPM
What is NPM?
Why do we need NPM?
Installing NPM?
A quick introduction to JavaScript IDEs
Visual Studio Code
Why Visual Studio Code?
Installing Visual Studio Code
Linux
Mac
Windows
Installing the plugins you will need
Configuring the testing environment
WebStorm
Why WebStorm?
Installing WebStorm
Linux
Mac
Windows
Installing the plugins you will need
Configuring the testing environment
Create React App
What is Create React App?
Installing the global module
Creating a React application
Running the Create React App script
Mocha and Chai
Jest
Mocha
Chai
Sinon
Enzyme
Ejecting the React app
Configuring to use Mocha and Chai
A quick kata to check our test setup
The requirements
The execution
Starting the kata
Summary
What to Know Before Getting Started
Untestable code
Dependency Injection
Static
Singleton
Global state
Abstracting third-party software
Test doubles
Mocking frameworks
The SOLID principles
The Single Responsibility Principle
The Open/Closed principle
The Liskov Substitution principle
The Interface Segregation principle
The Dependency Inversion principle
Timely greeting
Fragile tests
False positives and false failures
Abstract DateTime
Test double types
Dummies
Dummy logger
Example in C#
Example in JavaScript
Stubs
Example in C#
Example in JavaScript
Spies
Example in C#
Example in JavaScript
Mocks
Example in C#
Example in JavaScript
Fakes
Example in C#
Example in JavaScript
N-Tiered example
Presentation layer
Moq
Business layer
Summary
Tabula Rasa – Approaching an Application with TDD in Mind
Where to begin
Yak shaving
Big design up front
A clean slate
One bite at a time
Minimum Viable Product
Different mindset
YAGNI – you aren't gonna need it
Test small
Devil's advocate
Test negative cases first
When testing is painful
A spike
Assert first
Stay organized
Breaking down Speaker Meet
Speakers
Communities
Conferences
Technical requirements
Summary
Approaching the Problem
Defining the problem
Digesting the problem
Epics, features, and stories; oh my!
Epics
Features
Stories
Maintain your backlog
The Speaker Meet problem
Meaningful separation
Speakers
Communities
Conferences
Separate by team function
Technical separations
Technical requirements
React web user interface
.NET Core
.NET Web API
Entity Framework
Azure
Database
An N-Tiered hexagonal architecture
Hexagonal architecture
Basic yet effective N-Tiered divisions
Service layer
Microservices
Data access layer
Repository Pattern
Generic repository
User interface adapter layer
User interface layer
Front-end business layer
Front-end user interface layer
Front-end data source layer
Testing direction
Back-to-front
Defining a data source
Creating a business layer
Building a user interface
Front-to-back
Defining a user interface
Creating a business layer
Building a data source
Inside out
Defining a business layer
Summary
Test-Driving C# Applications
Reviewing the requirements
Speaker listing
API
API tests
Moq
Testing exception cases
Service
Service tests
Clean tests
Repository
The IRepository interface
FakeRepository
Using factories with the FakeRepository
Soft delete
Speaker details
API
API tests
Service
Service tests
Clean the tests
More from the repository
Additional factory work
Testing exception cases
Summary
Abstract Away Problems
Abstracting away problems
Gravatar
Starting with an interface
Implementing a test version of the interface
Implementing the production version of the interface
Future planning
Abstracting the data layer
Extending the repository pattern
The Get method
The GetAll method
The Create method
The Delete method
The Update method
Ensuring functionality
Creating a speaker
Getting a single speaker
Getting multiple speakers
Updating a speaker
Deleting a speaker
Genericizing the repository
Step one – abstract interface
Step two – abstract the concrete class
Converting Create to a generic method
Converting Get to a generic method
Converting GetAll to a generic method
Converting Update to a generic method
Converting Delete to a generic method
Step three – reorient the tests to use the generic repository
InMemoryRepository Create tests
InMemoryRepository Get tests
InMemoryRepository GetAll tests
InMemoryRepository Update tests
Entity Framework
DbContext
Models
Generic repository
Dependency Injection
Wire it all up
Postman
Summary
Testing JavaScript Applications
Creating a React app
Ejecting the app
Configuring Mocha, Chai, Enzyme, and Sinon
The plan
Considering the React component
Looking at Redux testability
The store
Actions
Reducers
Unit-testing an API service
Speaker listing
A mock API service
The Get All Speakers action
Testing a standard action
Testing a thunk
The Get All Speakers reducer
The Speaker listing component
Speaker detail
Adding to the mock API Service
The Get Speaker action
The Get Speaker reducer
The Speaker Detail component
Summary
Exploring Integrations
Implementing a real API service
Replacing the mock API with the real API service
Using Sinon to mock Ajax responses
Fixing existing tests
Mocking the server
Application configuration
End-to-end integration tests
Benefits
Detriments
How much end-to-end testing should you do?
Configuring the API project
Integration test project
Where to begin?
Verifying the repository calls into the DB context
InMemory database
Adding speakers to the InMemory database
Verify that the service calls the DB through the repository
ContextFixture
Verify the API calls into the service
TestServer
ServerFixture
Summary
Changes in Requirements
Hello World
A change in requirements
Good evening
FizzBuzz
A new feature
Number not found
TODO app
Mark complete
Adding tests
Production code
But don't remove from the list!
Adding tests
Production code
Changes to Speaker Meet
Changes to the back-end
Changes to the front-end
Sorted by rating on client side
What now?
Premature optimization
Summary
The Legacy Problem
What is legacy code?
Why does code go bad?
When does a project become legacy?
What can be done to prevent legacy decay?
Typical issues resulting from legacy code
Unintended side effects
Open Closed Principle and legacy code
Liskov Substitution Principle and legacy code
Over-optimization
Overly clever code
Tight coupling to third-party software
Issues that prevent adding tests
Direct dependence on framework and third-party code
Law of Demeter
Work in the constructor
Global state
Static methods
Large classes and functions
Dealing with legacy problems
Safe refactoring
Converting values to variables
Extracting a method
Extracting a class
Abstracting third-party libraries and framework code
Early tests
Gold standard tests
Testing all potential outcomes
Moving forward
Fixing bugs
Free to do unsafe refactoring
Summary
Unraveling a Mess
Inheriting code
The game
A change is requested
Life sometimes hands you lemons
Getting started
Abstracting a third-party class
Unexpected Input
Making sense of the madness
Final beautification
Ready for enhancements
Summary
A Better Foot Forward
What we've covered
Moving forward
TDD is a personal practice
You don't need permission
Grow applications through tests
Introducing TDD to your team
Don’t force TDD on anyone
Gamification of TDD
Showing your team the benefits
Review the results
Rejoining the world as a TDD expert
Seek a mentor
Becoming a mentor
Practice, practice, practice
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜