Practical test-driven development using C# 7 unleash the power of TDD by implementing real world examples under .NET environment and JavaScript
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 bu...
Otros Autores: | , , |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
Birmingham, England ; Mumbai, [India] :
Packt
2018.
|
Edición: | 1st edition |
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009631646206719 |
Tabla de Contenidos:
- Cover
- Copyright and Credits
- Packt Upsell
- Foreword
- Contributors
- Table of Contents
- Preface
- Chapter 1: 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
- Chapter 2: 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
- Chapter 3: 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
- Chapter 4: 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.
- Chapter 5: 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
- Chapter 6: 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
- Chapter 7: 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
- Chapter 8: 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
- Chapter 9: 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
- Chapter 10: 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
- Chapter 11: 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
- Chapter 12: 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.