Search This Blog

2021-03-03

Use of XUnit in .NET Core application - Part 04: Mocking and Test Coverage

 

Model Error










Mocking – Set Object

If we have to mock below httpcontext class, model and loginservice I order to do unit test of login method











Test Method

Mocking of httpcontext in constructor




















Note the mock class and mock service and ReturnAsAsync and Mock.of shortcut



But as the email address is not using for password comparison, we can ignore that by below code







Final Test method















Test Coverage

Nuget Package – Coverlet

Add it to the Test Project

Run the below command



During CI CD, if you want to store the test coverage result.





No comments: