<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi" -->

---
title: Advanced Integration Tests for .NET 7 API with...
description: A deep-dive tutorial on writing advanced integration tests for .NET 7 APIs using WebApplicationFactory and NUnit. Covers creating a custom...
canonical: https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Advanced Integration Tests for .NET 7 API with WebApplicationFactory and NUnit | daily.dev
og:description: A deep-dive tutorial on writing advanced integration tests for .NET 7 APIs using WebApplicationFactory and NUnit. Covers creating a custom...
og:url: https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi
og:image: https://api.daily.dev/og/posts/0mbvHOUOi.png
og:image:alt: Advanced Integration Tests for .NET 7 API with WebApplicationFactory and NUnit
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.

# Advanced Integration Tests for .NET 7 API with WebApplicationFactory and NUnit

**[Code4IT](https://daily.dev/sources/code4it)** · 13 min read · 0 upvotes · 0 comments

## Summary

A deep-dive tutorial on writing advanced integration tests for .NET 7 APIs using WebApplicationFactory and NUnit. Covers creating a custom WebApplicationFactory subclass, overriding appsettings via AddInMemoryCollection, swapping dependencies with stub classes through ConfigureTestServices, resolving and testing concrete classes from the DI container via scoped service providers, and enabling console/debug logging during tests. Includes a full example combining all these techniques and links to the author's sample GitHub repo.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/advanced-integration-tests-webapplicationfactory>

## Questions this post answers

### How do I override a configuration value like appsettings.json InstanceName when using WebApplicationFactory in integration tests?

Use ConfigureAppConfiguration inside an overridden ConfigureWebHost method and call configurationBuilder.AddInMemoryCollection with a list of KeyValuePair entries. This adds or overrides keys such as InstanceName with a test-specific value like FromTests, even if the key already exists in appsettings.json. Call configurationBuilder.Sources.Clear() first to remove all other configuration sources entirely.

_daily.dev surfaces more ASP.NET Core testing techniques for developers tuning WebApplicationFactory setups._

### How do I replace a real dependency with a stub class in ASP.NET Core integration tests using WebApplicationFactory?

Register the stub inside builder.ConfigureTestServices by calling services.AddScoped with the interface and stub implementation, such as services.AddScoped<ISocialLinkParser, StubSocialLinkParser>(). This overrides the production registration so the stub is resolved instead, letting tests avoid calling external APIs with limited free quotas while still exercising the rest of the pipeline.

_developers wiring up dependency stubs for integration tests can find more patterns like this on daily.dev._

### Why can't I see application logs when running ASP.NET Core integration tests with WebApplicationFactory?

Logs are not output by default unless you add a logging provider inside ConfigureTestServices, for example services.AddLogging(builder => builder.AddConsole().AddDebug()). Because the appsettings logging configuration is still active, call ClearProviders() first to stop logs from being sent to production sinks like DataDog or SEQ during test runs.

_daily.dev helps developers debugging test visibility issues keep up with ASP.NET Core testing tricks._

## 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
- [Refactor tests to make them more readable](https://daily.dev/posts/refactor-tests-to-make-them-more-readable-pz0up2gic) · Damir's Corner · 1 upvotes · 0 comments
- [5 Architecture Tests You Should Add to Your .NET Projects](https://daily.dev/posts/5-architecture-tests-you-should-add-to-your-net-projects-srtuu4tjc) · Milan Jovanović · 20 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/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi)

```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":"Advanced Integration Tests for .NET 7 API with WebApplicationFactory and NUnit","url":"https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi"},"datePublished":"2026-10-04T13:07:19.354Z","dateModified":"2026-10-04T13:16:17.292Z","description":"A deep-dive tutorial on writing advanced integration tests for .NET 7 APIs using WebApplicationFactory and NUnit. Covers creating a custom...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2fdd87715e4a4250fdb85151496b78dd?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2fdd87715e4a4250fdb85151496b78dd?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","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":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,c#,aspnet","timeRequired":"PT13M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"Advanced Integration Tests for .NET 7 API with WebApplicationFactory and NUnit"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/advanced-integration-tests-for-net-7-api-with-webapplicationfactory-and-nunit-0mbvhouoi#faq","mainEntity":[{"@type":"Question","name":"How do I override a configuration value like appsettings.json InstanceName when using WebApplicationFactory in integration tests?","acceptedAnswer":{"@type":"Answer","text":"Use ConfigureAppConfiguration inside an overridden ConfigureWebHost method and call configurationBuilder.AddInMemoryCollection with a list of KeyValuePair entries. This adds or overrides keys such as InstanceName with a test-specific value like FromTests, even if the key already exists in appsettings.json. Call configurationBuilder.Sources.Clear() first to remove all other configuration sources entirely. daily.dev surfaces more ASP.NET Core testing techniques for developers tuning WebApplicationFactory setups."}},{"@type":"Question","name":"How do I replace a real dependency with a stub class in ASP.NET Core integration tests using WebApplicationFactory?","acceptedAnswer":{"@type":"Answer","text":"Register the stub inside builder.ConfigureTestServices by calling services.AddScoped with the interface and stub implementation, such as services.AddScoped<ISocialLinkParser, StubSocialLinkParser>(). This overrides the production registration so the stub is resolved instead, letting tests avoid calling external APIs with limited free quotas while still exercising the rest of the pipeline. developers wiring up dependency stubs for integration tests can find more patterns like this on daily.dev."}},{"@type":"Question","name":"Why can't I see application logs when running ASP.NET Core integration tests with WebApplicationFactory?","acceptedAnswer":{"@type":"Answer","text":"Logs are not output by default unless you add a logging provider inside ConfigureTestServices, for example services.AddLogging(builder => builder.AddConsole().AddDebug()). Because the appsettings logging configuration is still active, call ClearProviders() first to stop logs from being sent to production sinks like DataDog or SEQ during test runs. daily.dev helps developers debugging test visibility issues keep up with ASP.NET Core testing tricks."}}]}
```

