.NET 6 Minimal APIs: Testing Strategies

Minimal APIs are great, but how do you test them without a `Startup` class?

WebApplicationFactory

You must expose the internal `Program` class to your test project.

// Program.cs
var app = builder.Build();
// ...
app.Run();

// Hack to make it visible
public partial class Program { }

Now you can use `WebApplicationFactory<Program>` in xUnit to spin up the in-memory server.


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.