Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

ASP.NET Core docs
ASP.NET Core
Getting Started with ASP.NET CoreProject Structure and ConfigurationCore ConceptsData, Validation and AuthenticationTestingDeployment
Discussions

ASP.NET Core guide · 5/6

Testing

ASP.NET Core apps are usually tested at two levels: unit tests for services and logic, and integration tests that host the whole app in memory with WebApplicationFactory. xUnit is the most widely used test framework in .NET; NUnit and MSTest work in the same way.

Create a test project

dotnet new xunit -o tests/TodoApi.Tests
dotnet add tests/TodoApi.Tests/TodoApi.Tests.csproj reference src/TodoApi/TodoApi.csproj
dotnet add tests/TodoApi.Tests/TodoApi.Tests.csproj package Microsoft.AspNetCore.Mvc.Testing
dotnet sln add tests/TodoApi.Tests/TodoApi.Tests.csproj
dotnet test

dotnet test builds and runs every test project in the solution; editors show the same tests in a test explorer.

Unit tests

Plain classes need no web host at all:

public static class Slug
{
    public static string Create(string title) =>
        string.Join('-', title.ToLowerInvariant().Split(' ', StringSplitOptions.RemoveEmptyEntries));
}
public class SlugTests
{
    [Fact]
    public void Joins_words_with_hyphens()
    {
        Assert.Equal("hello-asp-net", Slug.Create("Hello ASP NET"));
    }

    [Theory]
    [InlineData("  spaced   out ", "spaced-out")]
    [InlineData("One", "one")]
    public void Normalizes_input(string input, string expected)
    {
        Assert.Equal(expected, Slug.Create(input));
    }
}

[Fact] marks a single test and [Theory] runs the same test for each [InlineData] row. When a service has dependencies, depend on interfaces or abstractions such as TimeProvider so tests can pass fakes, written by hand or with a library like NSubstitute or Moq.

Integration tests with WebApplicationFactory

WebApplicationFactory<TEntryPoint> from Microsoft.AspNetCore.Mvc.Testing starts the app on an in-memory test server and hands you an HttpClient. It runs the real Program.cs, configuration and DI, so routing, middleware and serialization are all exercised.

With top-level statements, the compiler-generated Program class is not public. Newer SDKs can generate the declaration below for you; adding it at the end of Program.cs works with every version:

public partial class Program { }
using System.Net;
using System.Net.Http.Json;
using Microsoft.AspNetCore.Mvc.Testing;

public class TodoApiTests(WebApplicationFactory<Program> factory)
    : IClassFixture<WebApplicationFactory<Program>>
{
    [Fact]
    public async Task Get_unknown_todo_returns_404()
    {
        var client = factory.CreateClient();

        var response = await client.GetAsync("/todos/999");

        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    }

    [Fact]
    public async Task Post_then_get_returns_the_todo()
    {
        var client = factory.CreateClient();

        var created = await client.PostAsJsonAsync("/todos", new { title = "Write tests" });
        created.EnsureSuccessStatusCode();
        var todo = await created.Content.ReadFromJsonAsync<Todo>();

        var fetched = await client.GetFromJsonAsync<Todo>($"/todos/{todo!.Id}");
        Assert.Equal("Write tests", fetched!.Title);
    }
}

IClassFixture creates one app per test class and shares it between that class's tests, so tests should not depend on each other's data.

Customizing the test host

Derive from WebApplicationFactory to choose the environment or replace services. ConfigureTestServices runs after the app's own registrations:

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Time.Testing;

public class TodoApiFactory : WebApplicationFactory<Program>
{
    public FakeTimeProvider Time { get; } = new();

    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder.UseEnvironment("Testing");
        builder.ConfigureTestServices(services =>
        {
            services.RemoveAll<TimeProvider>();
            services.AddSingleton<TimeProvider>(Time);
        });
    }
}

FakeTimeProvider comes from the Microsoft.Extensions.TimeProvider.Testing package; tests call Time.Advance(...) to move the clock. For the database, point the Testing environment at a throwaway database, or start a real one in Docker with Testcontainers.

dotnet test --filter "FullyQualifiedName~TodoApiTests"
dotnet test --collect:"XPlat Code Coverage"

Summary

  • Create an xUnit project with dotnet new xunit and run it with dotnet test.
  • Unit-test services directly; keep dependencies replaceable.
  • WebApplicationFactory<Program> hosts the real app in memory for integration tests.
  • Override the environment and services in a custom factory with ConfigureTestServices.
Questions about this chapter?
Previous chapterData, Validation and AuthenticationNext chapterDeployment

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.