Single File Test Suites in Dotnet Csharp
This article is part of the 2025 Advent of C# Code Calendar, which publishes 2 C# articles every day in December leading up to 25 December.
NOTE: Originally targeted xUnit v2; now updated to xUnit.v3.
Introduction
One of my favorite new features in .NET 10 is C# file-based apps (or file-based C# programs if you prefer). With this feature, we can create individual .cs files and then run them using dotnet run <file.cs>. On Unix OSes you can go even further and mark the files as executable and include a shebang (#!) directive as the first line to tell the OS what to run it with and then you can run the files directly without even calling dotnet run.