X

Testing

Using query strings in ASP.NET Core unit tests

Using query string in controller unit tests is actually easy until we don’t need anything more advanced. We can buld up a string with query parameters and go with it. But what if things get more complex and we need encoding or multiple values? Here’s how to build safe query string for ASP.NET COre controller unit tests.

Inject users and roles dynamically to ASP.NET Core integration tests

After getting fake authenticated user to ASP.NET Core integration tests I made step further and introduced the way to use different user accounts. Using multiple users and roles instead of one test users is very common scenario in web applications. During my carreer I have seen only few business applications that doesn’t use different roles. This blog post demonstrates how to inject users dynamically to ASP.NET Core integration tests.

Create fake user for ASP.NET Core integration tests

After getting done with fake users for ASP.NET Core controller unit tests I wanted to make fake users available also in integration tests. It took some inventing and hacking but I made it work. This blog post shows you how to create fake users for ASP.NET Core integration tests and write effective extension methods to keep integration tests shorter.

Create fake user for ASP.NET Core controller tests

I think most of ASP.NET Core applications have authentication enabled. When writing unit tests for controllers we have one set of tests that need authenticated user and other set of tests that need anonymous user. Faking User property of controller is a little bit tricky. This blog post shows how to do it.

File uploads in ASP.NET Core integration tests

Writing integration tests for ASP.NET Core controller actions used for file uploads is not a rare need. It is fully supported by ASP.NET Core integration tests system. This post shows how to write integration tests for single and multiple file uploads.

Using ASP.NET Core Identity user accounts in integration tests

I have application that uses ASP.NET Core Identity with classic logins and there’s need to cover this application with integration tests. Some tests are for anonymous users and others for authenticated users. This blog post shows how to set selectively set authenticated ASP.NET Core Identity user for ASP.NET Core integration tests.

Using custom startup class with ASP.NET Core integration tests

My previous post demonstrated how to use custom appsettings.js file with integration tests in ASP.NET Core. But in practice it’s not enough and very often we need custom startup class that extends the one in web application project to configure application for integration tests. This blog post shows how to do it.

Using custom appsettings.json with ASP.NET Core integration tests

ASP.NET Core introduced the concept of TestServer for integration testing of web applications. Integration tests need web application run with all bells and whistles to make sure that all components work together with no flaws. Often we need special settings for integration tests as web application cannot use live services and easiest way to do it is to use special appsettings.json file. This blog post shows how to do it.

Fail build on Azure DevOps for low code coverage

As my ASP.NET Core code coverage reports work nice in Azure DevOps build pipeline I took step forward and made builds fail on Azure DevOps if percent of lines covered is below 60. This blog post shows how to do it using ReportGenerator and Build Quality Checks build tasks.

How to exclude code from code coverage

Recently I blogged about how to generate nice code coverage reports for ASP.NET Core and .NET Core applications. This blog post focuses on how to leave out from code coverage all code that will not be covered with unit tests and get numbers shown on code coverage reports correct.