Unit Testing an ASP.NET Core Web API
Unit testing your ASP.NET Core Web API helps with improving its reliability. This course will teach you the ins and outs of unit testing with xUnit in detail.
What you'll learn
Unit testing improves the reliability of your application. In this course, Unit Testing in ASP.NET Core Web API, you’ll learn the ins and outs of unit testing with xUnit.net.
First, you’ll explore the arrange, act, and assert pattern by covering core unit testing scenarios like asserting on strings, collections, and exceptions. Next, you’ll discover different approaches to set up your test context, work with data-driven tests, and how to isolate tests.
Finally, you’ll learn different approaches to testing API-specific concerns like testing controllers, middleware, and filters. At the end of the course, you’ll learn how to integrate testing in your workflow.
When you’re finished with this course, you’ll have the skills and knowledge needed to improve your application reliability with unit testing.
Table of contents
- Coming Up 3m
- Positioning This Course 2m
- Course Prerequisites 1m
- Frameworks and Tooling 3m
- Demo - Introducing the Demo Scenario 6m
- The What, Why, and What Not of Unit Testing 3m
- Comparing Unit Tests, Integration Test, and Functional Tests 4m
- Demo - Adding a Unit Test Project 4m
- Demo - Writing Your First Unit Test 7m
- Naming Guidelines for Unit Tests 1m
- The Arrange, Act, Assert Pattern 2m
- Comparing xUnit, NUnit, and MSTest 2m
- Summary 1m
- Coming Up 1m
- Learning About Assertions 4m
- Demo - Asserting on Booleans 5m
- Demo - Asserting on Strings 12m
- Demo - Asserting on Numeric Values 4m
- Demo - Asserting on Floating Points with Precision 2m
- Demo - Introducing a Repository Implementation with Test Data 4m
- Demo - Asserting on Arrays and Collection Content 10m
- Demo - Asserting Asynchronous Code 3m
- Demo - Asserting on Exceptions 6m
- Demo - Asserting on Events 3m
- Demo - Asserting on Object Types 3m
- Asserting on Private Methods 2m
- Summary 1m
- Coming Up 1m
- Setting Up Tests and Sharing Test Context 3m
- Demo - Sharing Context with the Constructor and Dispose Approach 4m
- Demo - Sharing Context with the Class Fixture Approach 6m
- Demo - Sharing Context with the Collection Fixture Approach 5m
- Integrating Test Context with the ASP.NET Core Dependency Injection System 1m
- Demo - Integrating Test Context with the ASP.NET Core Dependency Injection System 5m
- Demo - Categorizing and Running Subsets of Tests 4m
- Demo - Skipping Tests 2m
- Demo - Adding Additional Test Output 3m
- Summary 2m
- Coming Up 1m
- Introducing Theories and Data-driven Tests 3m
- Demo - Testing a Theory with Inline Data 3m
- Demo - Testing a Theory with Member Data 6m
- Demo - Testing a Theory with Class Data 3m
- Demo - Testing a Theory with Strongly-typed Test Data 5m
- Getting Data from an External Source 1m
- Demo - Getting Data from an External Source 3m
- Summary 1m
- Coming Up 1m
- Investigating Test Isolation Approaches 5m
- Unit Testing with Entity Framework Core 3m
- Demo - Using SQLite In-memory Mode for Unit Testing 6m
- Unit Testing with HttpClient 2m
- Demo - Unit Testing with HttpClient 6m
- Introducing Moq 2m
- Demo - Creating and Using a Mock Object 6m
- Demo - Configuring Mock Object Return Values 8m
- Demo - Mocking an Interface 3m
- Demo - Mocking Async Code 2m
- Which Test Isolation Approach Should You Use? 2m
- Summary 1m
- Coming Up 1m
- Code Coverage and Deciding What to Unit Test 5m
- Introduction to Testing API Controllers 5m
- Demo - Verifying ActionResult Types when Testing 6m
- Demo - Verifying Model Types when Testing 4m
- Demo - Verifying Model Content when Testing 3m
- Demo - Combining Controller Action Asserts in One Unit Test and Testing Mapping Code 5m
- Demo - Dealing with AutoMapper Dependencies 4m
- Demo - Testing Validation and ModelState 5m
- Testing with HttpContext 2m
- Demo - Testing with HttpContext.Features 5m
- Demo - Testing with HttpContext.User 9m
- Demo - Testing with HttpClient Calls 10m
- Summary 1m
- Coming Up 1m
- Demo - Running Tests with the CLI 4m
- Test Runners Versus Test Frameworks 4m
- Running Tests in Parallel 1m
- Demo - Parallelism in Test Frameworks 5m
- Demo - Parallelism in Test Runners 3m
- Running Tests against Multiple Target Frameworks 1m
- Demo - Running Tests Against Multiple Target Frameworks 2m
- Integrating Unit Tests in Your CI/CD Pipeline 2m
- Demo - Integrating Unit Tests in Your CI/CD Pipeline 3m
- Summary 1m