万本电子书0元读

万本电子书0元读

顶部广告

Practical Test-Driven Development using C# 7电子书

售       价:¥

2人正在读 | 0人评论 9.8

作       者:John Callaway,Clayton Hunt

出  版  社:Packt Publishing

出版时间:2018-02-15

字       数:50.3万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Develop applications for the real world with a thorough software testing approach About This Book ? Develop a thorough understanding of TDD and how it can help you develop simpler applications with no defects using C# and JavaScript ? Adapt to the mindset of writing tests before code by incorporating business goals, code manageability, and other factors ? Make all your software units and modules pass tests by analyzing failed tests and refactoring code as and when required Who This Book Is For This book is for software developers with a basic knowledge of Test Driven Development (TDD) who want a thorough understanding of how TDD can benefit them and the applications they produce. The examples in this book are in C#, and you will need a basic understanding of C# to work through these examples. What You Will Learn ? The core concepts of TDD ? Testing in action with a real-world case study in C# and JavaScript using React ? Writing proper Unit Tests and testable code for your application ? Using different types of test double such as stubs, spies, and mocks ? Growing an application guided by tests ? Exploring new developments on a green-field application ? Mitigating the problems associated with writing tests for legacy applications ? Modifying a legacy application to make it testable In Detail Test-Driven Development (TDD) is a methodology that helps you to write as little as code as possible to satisfy software requirements, and ensures that what you've written does what it's supposed to do. If you're looking for a practical resource on Test-Driven Development this is the book for you. You've found a practical end-to-end guide that will help you implement Test-Driven Techniques for your software development projects. You will learn from industry standard patterns and practices, and shift from a conventional approach to a modern and efficient software testing approach in C# and JavaScript. This book starts with the basics of TDD and the components of a simple unit test. Then we look at setting up the testing framework so that you can easily run your tests in your development environment. You will then see the importance of defining and testing boundaries, abstracting away third-party code (including the .NET Framework), and working with different types of test double such as spies, mocks, and fakes. Moving on, you will learn how to think like a TDD developer when it comes to application development. Next, you'll focus on writing tests for new/changing requirements and covering newly discovered bugs, along with how to test JavaScript applications and perform integration testing. You’ll also learn how to identify code that is inherently un-testable, and identify some of the major problems with legacy applications that weren’t written with testability in mind. By the end of the book, you’ll have all the TDD skills you'll need and you’ll be able to re-enter the world as a TDD expert! Style and approach A practical step-by-step approach with real-world case studies.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部