Ardalis.SingleFileTestRunner
0.4.0
dotnet add package Ardalis.SingleFileTestRunner --version 0.4.0
NuGet\Install-Package Ardalis.SingleFileTestRunner -Version 0.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ardalis.SingleFileTestRunner" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ardalis.SingleFileTestRunner" Version="0.4.0" />
<PackageReference Include="Ardalis.SingleFileTestRunner" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ardalis.SingleFileTestRunner --version 0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ardalis.SingleFileTestRunner, 0.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ardalis.SingleFileTestRunner@0.4.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ardalis.SingleFileTestRunner&version=0.4.0
#tool nuget:?package=Ardalis.SingleFileTestRunner&version=0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SingleFileTestRunner
A lightweight package for running xUnit tests in single-file C# applications. Perfect for quick test scripts, learning scenarios, or standalone test executables.
Installation
dotnet add package Ardalis.SingleFileTestRunner
dotnet add package xunit
Quick Start
Create a single .cs file with your tests and run them directly:
// MyTests.cs
using Xunit;
using Ardalis.SingleFileTestRunner;
// Run all tests in this file
return await TestRunner.RunTestsAsync();
// Your test classes
public class CalculatorTests
{
[Fact]
public void Addition_ReturnsCorrectSum()
{
Assert.Equal(4, 2 + 2);
}
[Theory]
[InlineData(1, 1, 2)]
[InlineData(5, 3, 8)]
[InlineData(-1, 1, 0)]
public void Addition_WithVariousInputs_ReturnsExpectedResult(int a, int b, int expected)
{
Assert.Equal(expected, a + b);
}
}
public class StringTests
{
[Fact]
public void Contains_FindsSubstring()
{
Assert.Contains("world", "Hello world!");
}
}
Run with:
dotnet run MyTests.cs
Features
- Simple API: Just call
TestRunner.RunTestsAsync()to discover and run all xUnit tests - Colorized Output: Clear visual feedback with green for passing, red for failing, and yellow for skipped tests
- CI/CD Ready: Returns exit code 0 for success, 1 for failures
- Single-File Compatible: Works with
dotnet runon single.csfiles and published single-file executables - Full xUnit Support: Supports
[Fact],[Theory], and all standard xUnit attributes
Sample Output
Discovering and running tests...
[PASS] CalculatorTests.Addition_ReturnsCorrectSum
[PASS] CalculatorTests.Addition_WithVariousInputs_ReturnsExpectedResult(a: 1, b: 1, expected: 2)
[PASS] CalculatorTests.Addition_WithVariousInputs_ReturnsExpectedResult(a: 5, b: 3, expected: 8)
[PASS] CalculatorTests.Addition_WithVariousInputs_ReturnsExpectedResult(a: -1, b: 1, expected: 0)
[PASS] StringTests.Contains_FindsSubstring
Test run completed in 0.15s
Total tests: 5
Passed: 5
Use Cases
- Learning & Experimentation: Quickly test C# concepts without setting up a full test project
- Script-Based Testing: Create standalone test scripts that can be shared and run easily
- Single-File Deployments: Build self-contained test executables for distribution
- Prototyping: Rapidly prototype and validate code in a single file
- Parallel Testing: Run many test files in completely standalone processes, in parallel
Requirements
- .NET 10.0 or later
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- xunit (>= 2.9.2)
- xunit.runner.utility (>= 2.9.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
* Fix repo link in package metadata