<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0" -->

---
title: How to test ASP.NET Core Minimal APIs | daily.dev
description: A step-by-step tutorial shows how to write unit and integration tests for ASP.NET Core Minimal APIs using xUnit and the WebApplicationFactory class. It covers...
canonical: https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to test ASP.NET Core Minimal APIs | daily.dev
og:description: A step-by-step tutorial shows how to write unit and integration tests for ASP.NET Core Minimal APIs using xUnit and the WebApplicationFactory class. It covers...
og:url: https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0
og:image: https://api.daily.dev/og/posts/Ls8oXtEu0.png
og:image:alt: How to test ASP.NET Core Minimal APIs
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to test ASP.NET Core Minimal APIs

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 15 min read · 0 upvotes · 0 comments

## Summary

A step-by-step tutorial shows how to write unit and integration tests for ASP.NET Core Minimal APIs using xUnit and the WebApplicationFactory class. It covers testing a basic 'Hello World' endpoint, testing a POST endpoint with JSON payloads and validation via MiniValidation, and customizing the service collection to swap real services for test doubles like TestPeopleService.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2022-06-07-how-test-aspnetcore-minimal-apis>

## Questions this post answers

### How do I test an ASP.NET Core Minimal API endpoint with xUnit?

Use the Microsoft.AspNetCore.Mvc.Testing package's WebApplicationFactory<Program> class to spin up an in-memory test server and HttpClient. Add a public partial class Program declaration in Program.cs so the test project can reference it, then call application.CreateClient() and issue requests like client.GetStringAsync("/") inside an xUnit [Fact] test, asserting on the response.

_Developers wiring up test suites for minimal APIs can find more patterns like this through daily.dev._

### How can I replace a real service implementation with a test double in ASP.NET Core integration tests?

Use WebApplicationFactory<Program>.WithWebHostBuilder() combined with ConfigureServices() to re-register a service, such as swapping IPeopleService's real PeopleService implementation for a TestPeopleService using services.AddScoped<IPeopleService, TestPeopleService>(). For reuse across many tests, this logic can be moved into a custom class overriding WebApplicationFactory<T>.CreateHost().

_Teams standardizing their integration test setup can track techniques like service overrides via daily.dev._

## Similar posts on daily.dev

- [Testing ASP.NET Core Web API: WebApplicationFactory and Integration Tests](https://daily.dev/posts/testing-asp-net-core-web-api-webapplicationfactory-and-integration-tests-8chotq6j5) · We Are .NET · 1 upvotes · 0 comments
- [How to Migrate from ASP.NET Framework to ASP.NET Core](https://daily.dev/posts/how-to-migrate-from-asp-net-framework-to-asp-net-core-e22ntd3va) · freeCodeCamp · 4 upvotes · 0 comments
- [The .NET Tools Blog](https://daily.dev/posts/the-net-tools-blog-tdsv0g0uj) · JetBrains · 6 upvotes · 0 comments
- [How to Upgrade ASP.NET MVC to .NET Step by Step](https://daily.dev/posts/how-to-upgrade-asp-net-mvc-to-net-step-by-step-i3p1uesfs) · C\# Corner · 2 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#c#](https://daily.dev/tags/c#), [#aspnet](https://daily.dev/tags/aspnet)

[View this post on daily.dev](https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to test ASP.NET Core Minimal APIs","url":"https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0"},"datePublished":"2026-10-04T13:04:14.948Z","dateModified":"2026-10-04T13:05:52.431Z","description":"A step-by-step tutorial shows how to write unit and integration tests for ASP.NET Core Minimal APIs using xUnit and the WebApplicationFactory class. It covers...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/42b849534aa487559f522f256fd44de8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/42b849534aa487559f522f256fd44de8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,c#,aspnet","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"How to test ASP.NET Core Minimal APIs"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-test-asp-net-core-minimal-apis-ls8oxteu0#faq","mainEntity":[{"@type":"Question","name":"How do I test an ASP.NET Core Minimal API endpoint with xUnit?","acceptedAnswer":{"@type":"Answer","text":"Use the Microsoft.AspNetCore.Mvc.Testing package's WebApplicationFactory<Program> class to spin up an in-memory test server and HttpClient. Add a public partial class Program declaration in Program.cs so the test project can reference it, then call application.CreateClient() and issue requests like client.GetStringAsync(\"/\") inside an xUnit [Fact] test, asserting on the response. Developers wiring up test suites for minimal APIs can find more patterns like this through daily.dev."}},{"@type":"Question","name":"How can I replace a real service implementation with a test double in ASP.NET Core integration tests?","acceptedAnswer":{"@type":"Answer","text":"Use WebApplicationFactory<Program>.WithWebHostBuilder() combined with ConfigureServices() to re-register a service, such as swapping IPeopleService's real PeopleService implementation for a TestPeopleService using services.AddScoped<IPeopleService, TestPeopleService>(). For reuse across many tests, this logic can be moved into a custom class overriding WebApplicationFactory<T>.CreateHost(). Teams standardizing their integration test setup can track techniques like service overrides via daily.dev."}}]}
```

