TUnit.Assertions.Analyzers
0.1.767
Prefix Reserved
TUnit.Assertions handles analyzing natively now.
See the version list below for details.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.767
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.767
<PackageReference Include="TUnit.Assertions.Analyzers" Version="0.1.767" />
paket add TUnit.Assertions.Analyzers --version 0.1.767
#r "nuget: TUnit.Assertions.Analyzers, 0.1.767"
// Install TUnit.Assertions.Analyzers as a Cake Addin #addin nuget:?package=TUnit.Assertions.Analyzers&version=0.1.767 // Install TUnit.Assertions.Analyzers as a Cake Tool #tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.767
TUnit
A modern, flexible and fast testing framework for .NET 8 and up. With Native AOT and Trimmed Single File application support included!
Documentation
See here: https://thomhurst.github.io/TUnit/
IDE
TUnit is built on top of the newer Microsoft.Testing.Platform, as opposed to the older VSTest platform. Because the infrastructure behind the scenes is new and different, you may need to enable some settings. This should just be a one time thing.
Visual Studio
Visual Studio is supported.
Rider
Rider is supported. The Enable Testing Platform support option must be selected in Settings > Build, Execution, Deployment > Unit Testing > VSTest.
<img src="/docs/static/img/rider.png" height="300px">
VS Code
Visual Studio Code is supported.
- Install the extension Name: C# Dev Kit
- Go to the C# Dev Kit extension's settings
- Enable Dotnet > Test Window > Use Testing Platform Protocol
<img src="/docs/static/img/visual-studio-code.png" height="300px">
CLI
dotnet
CLI - Fully supported. Tests should be runnable with dotnet test
, dotnet run
, dotnet exec
or executing an executable directly. See the docs for more information!
Features
- Native AOT / Trimmed Single File application support
- Source generated tests
- Dependency injection support (See here)
- Full async support
- Parallel by default, with mechanisms to:
- Run specific tests completely on their own
- Run specific tests not in parallel with other specific tests
- Limit the parallel limit on a per-test, class or assembly level
- Test ordering (if running not in parallel)
- Tests can depend on other tests to form chains, useful for if one test depends on state from another action
- Easy to read assertions
- Injectable test data via classes, methods, compile-time args, or matrices
- Hooks before and after:
- TestDiscover
- TestSession
- Assembly
- Class
- Test
- Designed to avoid common pitfalls such as leaky test states
- Ability to view and interrogate metadata and results from various assembly/class/test context objects
Installation
dotnet add package TUnit --prerelease
Example test
private static readonly TimeOnly Midnight = TimeOnly.FromTimeSpan(TimeSpan.Zero);
private static readonly TimeOnly Noon = TimeOnly.FromTimeSpan(TimeSpan.FromHours(12));
[Test]
public async Task IsMorning()
{
var time = GetTime();
await Assert.That(time).IsAfterOrEqualTo(Midnight)
.And.IsBefore(Noon);
}
or with more complex test orchestration needs
[Before(Class)]
public static async Task ClearDatabase(ClassHookContext context) { ... }
[After(Class)]
public static async Task AssertDatabaseIsAsExpected(ClassHookContext context) { ... }
[Before(Test)]
public async Task CreatePlaywrightBrowser(TestContext context) { ... }
[After(Test)]
public async Task DisposePlaywrightBrowser(TestContext context) { ... }
[Retry(3)]
[Test, DisplayName("Register an account")]
[MethodData(nameof(GetAuthDetails))]
public async Task Register(string username, string password) { ... }
[Repeat(5)]
[Test, DependsOn(nameof(Register))]
[MethodData(nameof(GetAuthDetails))]
public async Task Login(string username, string password) { ... }
[Test, DependsOn(nameof(Login), [typeof(string), typeof(string)])]
[MethodData(nameof(GetAuthDetails))]
public async Task DeleteAccount(string username, string password) { ... }
[Category("Downloads")]
[Timeout(300_000)]
[Test, NotInParallel(Order = 1)]
public async Task DownloadFile1() { ... }
[Category("Downloads")]
[Timeout(300_000)]
[Test, NotInParallel(Order = 2)]
public async Task DownloadFile2() { ... }
[Repeat(10)]
[Test]
[Arguments(1)]
[Arguments(2)]
[Arguments(3)]
[DisplayName("Go to the page numbered $page")]
public async Task GoToPage(int page) { ... }
[Category("Cookies")]
[Test, Skip("Not yet built!")]
public async Task CheckCookies() { ... }
[Test, Explicit, WindowsOnlyTest, RetryHttpServiceUnavailable(5)]
[Property("Some Key", "Some Value")]
public async Task Ping() { ... }
[Test]
[ParallelLimit<LoadTestParallelLimit>]
[Repeat(1000)]
public async Task LoadHomepage() { ... }
public static IEnumerable<(string Username, string Password)> GetAuthDetails()
{
yield return ("user1", "password1");
yield return ("user2", "password2");
yield return ("user3", "password3");
}
public class WindowsOnlyTestAttribute : SkipAttribute
{
public WindowsOnlyTestAttribute() : base("Windows only test")
{
}
public override Task<bool> ShouldSkip(TestContext testContext)
{
return Task.FromResult(!OperatingSystem.IsWindows());
}
}
public class RetryHttpServiceUnavailableAttribute : RetryAttribute
{
public RetryHttpServiceUnavailableAttribute(int times) : base(times)
{
}
public override Task<bool> ShouldRetry(TestInformation testInformation, Exception exception, int currentRetryCount)
{
return Task.FromResult(exception is HttpRequestException { StatusCode: HttpStatusCode.ServiceUnavailable });
}
}
public class LoadTestParallelLimit : IParallelLimit
{
public int Limit => 50;
}
Motivations
TUnit is inspired by NUnit and xUnit - two of the most popular testing frameworks for .NET.
It aims to build upon the useful features of both while trying to address any pain points that they may have.
Benchmark
Scenario: Building the test project
ubuntu-latest
BenchmarkDotNet v0.14.0, Ubuntu 22.04.5 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.613 s | 0.0312 s | 0.0371 s |
Build_NUnit | 1.451 s | 0.0243 s | 0.0227 s |
Build_xUnit | 1.412 s | 0.0209 s | 0.0175 s |
Build_MSTest | 1.434 s | 0.0261 s | 0.0231 s |
macos-latest
BenchmarkDotNet v0.14.0, macOS Sonoma 14.6.1 (23G93) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
DefaultJob : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
Build_TUnit | 930.4 ms | 47.32 ms | 138.03 ms | 892.4 ms |
Build_NUnit | 708.0 ms | 12.41 ms | 11.00 ms | 707.5 ms |
Build_xUnit | 708.4 ms | 7.78 ms | 7.27 ms | 708.8 ms |
Build_MSTest | 758.0 ms | 5.98 ms | 5.30 ms | 758.5 ms |
windows-latest
BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2700) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.483 s | 0.0295 s | 0.0303 s |
Build_NUnit | 1.353 s | 0.0185 s | 0.0173 s |
Build_xUnit | 1.364 s | 0.0173 s | 0.0153 s |
Build_MSTest | 1.365 s | 0.0167 s | 0.0157 s |
Scenario: A single test that completes instantly (including spawning a new process and initialising the test framework)
ubuntu-latest
BenchmarkDotNet v0.14.0, Ubuntu 22.04.5 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 47.12 ms | 0.929 ms | 2.261 ms |
TUnit | 742.85 ms | 14.750 ms | 19.180 ms |
NUnit | 1,318.15 ms | 9.880 ms | 8.759 ms |
xUnit | 1,302.05 ms | 13.606 ms | 12.727 ms |
MSTest | 1,171.58 ms | 14.299 ms | 12.675 ms |
windows-latest
BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2700) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 83.38 ms | 1.648 ms | 3.404 ms |
TUnit | 783.74 ms | 15.563 ms | 21.817 ms |
NUnit | 1,360.60 ms | 14.801 ms | 13.121 ms |
xUnit | 1,345.95 ms | 8.278 ms | 6.912 ms |
MSTest | 1,220.28 ms | 13.593 ms | 12.715 ms |
macos-latest
BenchmarkDotNet v0.14.0, macOS Sonoma 14.6.1 (23G93) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
DefaultJob : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Method | Mean | Error | StdDev | Median |
---|---|---|---|---|
TUnit_AOT | 158.1 ms | 15.87 ms | 46.29 ms | 155.4 ms |
TUnit | 614.2 ms | 35.83 ms | 105.09 ms | 590.9 ms |
NUnit | 1,045.0 ms | 49.17 ms | 144.20 ms | 1,021.2 ms |
xUnit | 821.8 ms | 45.04 ms | 129.22 ms | 780.0 ms |
MSTest | 839.7 ms | 17.30 ms | 48.50 ms | 842.6 ms |
Scenario: A test that takes 50ms to execute, repeated 100 times (including spawning a new process and initialising the test framework)
ubuntu-latest
BenchmarkDotNet v0.14.0, Ubuntu 22.04.5 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 81.35 ms | 1.484 ms | 1.239 ms |
TUnit | 851.84 ms | 16.988 ms | 20.863 ms |
NUnit | 6,380.26 ms | 16.997 ms | 15.068 ms |
xUnit | 6,475.34 ms | 22.062 ms | 20.637 ms |
MSTest | 6,380.68 ms | 21.059 ms | 19.699 ms |
windows-latest
BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2700) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 130.9 ms | 2.78 ms | 8.20 ms |
TUnit | 831.1 ms | 16.08 ms | 25.04 ms |
NUnit | 7,496.0 ms | 15.49 ms | 14.49 ms |
xUnit | 7,497.7 ms | 12.14 ms | 11.35 ms |
MSTest | 7,419.0 ms | 15.15 ms | 13.43 ms |
macos-latest
BenchmarkDotNet v0.14.0, macOS Sonoma 14.6.1 (23G93) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 8.0.401
[Host] : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
DefaultJob : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 241.7 ms | 11.71 ms | 34.52 ms |
TUnit | 614.6 ms | 19.77 ms | 58.28 ms |
NUnit | 14,298.4 ms | 283.86 ms | 573.40 ms |
xUnit | 14,545.5 ms | 289.23 ms | 577.63 ms |
MSTest | 14,525.8 ms | 289.72 ms | 591.83 ms |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
0.1.984 | 767 | 10/7/2024 | |
0.1.980 | 94 | 10/7/2024 | |
0.1.971 | 91 | 10/7/2024 | |
0.1.966 | 107 | 10/7/2024 | |
0.1.962 | 96 | 10/6/2024 | |
0.1.961 | 98 | 10/6/2024 | |
0.1.958 | 94 | 10/6/2024 | |
0.1.954 | 106 | 10/6/2024 | |
0.1.949 | 93 | 10/6/2024 | |
0.1.942 | 101 | 10/5/2024 | |
0.1.939 | 96 | 10/5/2024 | |
0.1.937 | 96 | 10/5/2024 | |
0.1.934 | 92 | 10/5/2024 | |
0.1.931 | 98 | 10/5/2024 | |
0.1.928 | 99 | 10/4/2024 | |
0.1.923 | 98 | 10/4/2024 | |
0.1.916 | 95 | 10/3/2024 | |
0.1.911 | 106 | 10/3/2024 | |
0.1.897 | 124 | 10/2/2024 | |
0.1.894 | 96 | 10/2/2024 | |
0.1.891 | 99 | 10/2/2024 | |
0.1.885 | 101 | 10/1/2024 | |
0.1.877 | 102 | 9/29/2024 | |
0.1.872 | 111 | 9/29/2024 | |
0.1.869 | 105 | 9/29/2024 | |
0.1.864 | 100 | 9/28/2024 | |
0.1.863 | 103 | 9/28/2024 | |
0.1.857 | 98 | 9/28/2024 | |
0.1.842 | 105 | 9/26/2024 | |
0.1.827 | 103 | 9/25/2024 | |
0.1.818 | 100 | 9/24/2024 | |
0.1.817 | 98 | 9/24/2024 | |
0.1.816 | 97 | 9/24/2024 | |
0.1.812 | 109 | 9/23/2024 | |
0.1.807 | 98 | 9/23/2024 | |
0.1.804 | 120 | 9/22/2024 | |
0.1.801 | 109 | 9/22/2024 | |
0.1.797 | 98 | 9/22/2024 | |
0.1.793 | 118 | 9/21/2024 | |
0.1.791 | 96 | 9/21/2024 | |
0.1.790 | 95 | 9/21/2024 | |
0.1.783 | 108 | 9/20/2024 | |
0.1.773 | 105 | 9/20/2024 | |
0.1.767 | 103 | 9/19/2024 | |
0.1.763 | 102 | 9/19/2024 | |
0.1.762 | 106 | 9/19/2024 | |
0.1.759 | 106 | 9/19/2024 | |
0.1.752 | 101 | 9/18/2024 | |
0.1.741 | 104 | 9/17/2024 | |
0.1.738 | 126 | 9/16/2024 | |
0.1.732 | 123 | 9/16/2024 | |
0.1.720 | 123 | 9/15/2024 | |
0.1.716 | 125 | 9/15/2024 | |
0.1.714 | 117 | 9/15/2024 | |
0.1.711 | 111 | 9/15/2024 | |
0.1.703 | 333 | 9/14/2024 | |
0.1.697 | 211 | 9/14/2024 | |
0.1.691 | 336 | 9/13/2024 | |
0.1.686 | 181 | 9/13/2024 | |
0.1.672 | 400 | 9/12/2024 | |
0.1.667 | 215 | 9/11/2024 | |
0.1.664 | 150 | 9/11/2024 | |
0.1.653 | 268 | 9/11/2024 | |
0.1.639 | 338 | 9/10/2024 | |
0.1.634 | 186 | 9/10/2024 | |
0.1.623 | 324 | 9/7/2024 | |
0.1.600 | 583 | 9/6/2024 | |
0.1.582 | 345 | 9/5/2024 | |
0.1.578 | 143 | 9/5/2024 | |
0.1.575 | 133 | 9/4/2024 | |
0.1.518 | 371 | 9/2/2024 | |
0.1.512 | 1,149 | 8/30/2024 | |
0.1.508 | 139 | 8/29/2024 | |
0.1.506 | 214 | 8/28/2024 | |
0.1.505 | 153 | 8/28/2024 | |
0.1.504 | 140 | 8/28/2024 | |
0.1.503 | 184 | 8/27/2024 | |
0.1.502 | 144 | 8/27/2024 | |
0.1.497 | 141 | 8/27/2024 | |
0.1.495 | 146 | 8/27/2024 | |
0.1.486 | 146 | 8/9/2024 | |
0.1.481 | 296 | 8/8/2024 | |
0.1.479 | 154 | 8/8/2024 | |
0.1.474 | 147 | 8/7/2024 | |
0.1.471 | 177 | 8/7/2024 | |
0.1.470 | 128 | 8/7/2024 | |
0.1.467 | 140 | 8/7/2024 | |
0.1.455 | 132 | 7/31/2024 | |
0.1.454 | 106 | 7/30/2024 |