ASP.NET-Core-Unit-Testing-with-xUnit
ASP.NET-Core-Unit-Testing-with-xUnit copied to clipboard
How to perform Unit Testing with xUnit in ASP.NET Core
trafficstars
ASP.NET Core Unit Testing with xUnit
I perform Unit Testing for my ASP.NET core app with xUnit framework. These are divided into 6 topics:
- Unit Testing with xUnit in ASP.NET Core
- Moq and xUnit for Unit Testing Controllers in ASP.NET Core
- Unit Testing of Web API with xUnit and Moq
- How to tests Entity Framework Core Codes
- How to perform Integration Testing in ASP.NET Core
- Automated UI Testing with Selenium in ASP.NET Core
I have also written separate tutorials for each of these 6 types of tests. Kidly refer them.
Tutorial 1
How to perform Unit Testing with xUnit in ASP.NET Core
Contents
- Fact, Theory, InlineData
- Project Setup
- Adding Project for Unit Testing
- Adding Project Reference
- Adding xUnit Packages
- Testing a C# class functionality in xUnit
- Arrange, Act, Assert
- Running the Test in Test Explorer
- [Theory] and [InlineData] attributes
- Assert class Important Methods
- Testing Controller with xUnit
- Writing Test Methods for controllers in xUnit
- How to Debug Test Methods with Breakpoints
Tutorial 2
How to use Moq and xUnit for Unit Testing Controllers in ASP.NET Core
Contents
- Setup
- Moq
- In Memory Database
- Creating Database Operations Class
- Creating a Simple CRUD Operations feature in ASP.NET Core
- Testing Controller with Moq and xUnit
- Unit Tests for “Create” actions
- Unit Tests for “Read” action
- Unit Tests for “Update” action
- Unit Tests for “Delete” action
Tutorial 3
Unit Testing of Web API with xUnit and Moq
Contents
- Project setup install xUnit and Moq
- Create Web API
- Testing Web API with xUnit and Moq
Tutorial 4
How to tests Entity Framework Core Codes
Contents
- Setup of the App and In-Memory database for Testing
- In Memory Database
- Database Context and Model class
- Creating a Simple CRUD Operations feature in ASP.NET Core
- Testing Controller with xUnit
- Seeding the Database
- Unit Tests for “Create” actions
- Unit Tests for “Read” action
- Unit Tests for “Update” action
- Unit Tests for “Delete” action
Tutorial 5
How to perform Integration Testing in ASP.NET Core
Contents
- Project Setup
- Creating Test Server with WebApplicationFactory<T> class
- Integration Test Class
- Integration Testing of the Read Action
- Integration Testing of the CREATE Action (HTTP GET type)
- Invalid Model – Integration Testing of the CREATE Action (HTTP POST type)
- Valid Model – Integration Testing of the CREATE Action (HTTP POST type)
- AntiForgeryToken in Integration Testing
- How to include AntiForgeryToken in Integration Testing
- Modify the Integration Test for ValidateAntiForgeryToken
Tutorial 6
Automated UI Testing with Selenium in ASP.NET Core
Contents
- Project Setup and Selenium Installation
- Writing UI tests with Selenium
- UI Test to Check if the View is rendered
- UI Test to Check browser behaviour when Model is invalid
- UI Test to Check browser behaviour for Valid Model
Want to support me ?
Your support of every $5 will be a great reward for me to carry on my work. Thank you!

