TUnit.Assertions.Analyzers
0.1.600
Prefix Reserved
TUnit.Assertions handles analyzing natively now.
See the version list below for details.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.600
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.600
<PackageReference Include="TUnit.Assertions.Analyzers" Version="0.1.600" />
paket add TUnit.Assertions.Analyzers --version 0.1.600
#r "nuget: TUnit.Assertions.Analyzers, 0.1.600"
// Install TUnit.Assertions.Analyzers as a Cake Addin #addin nuget:?package=TUnit.Assertions.Analyzers&version=0.1.600 // Install TUnit.Assertions.Analyzers as a Cake Tool #tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.600
TUnit
A modern, flexible and fast testing framework for .NET 8 and up.
Documentation
See here: https://thomhurst.github.io/TUnit/
IDE
TUnit is built on top of newer Microsoft.Testing.Platform libraries, as opposed to older legacy VSTest libraries. As of July 2024, IDEs do not fully support this testing platform yet.
Visual Studio Preview versions can run the new tests by enabling the new testing platform server mode, within Visual Studio preview/experimental features. You will have to opt in to this manually.
For Rider, it is not yet supported. I believe they are working on it so we just have to wait for now.
dotnet
CLI - Fully supported. Tests should be runnable with both dotnet test
or dotnet run
. dotnet run
should give you a better experience and make it simpler to pass in test flags!
Features
- Source generated tests
- 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 a 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
[Test]
public async Task Test1()
{
var value = "Hello world!";
await Assert.That(value)
.Is.Not.Null
.And.Does.StartWith("H")
.And.Has.Count().EqualTo(12)
.And.Is.EqualTo("hello world!", StringComparison.InvariantCultureIgnoreCase);
}
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")]
[EnumerableMethodData(nameof(GetAuthDetails))]
public async Task Register(string username, string password) { ... }
[Repeat(5)]
[Test, DependsOn(nameof(Register))]
[EnumerableMethodData(nameof(GetAuthDetails))]
public async Task Login(string username, string password) { ... }
[Test, DependsOn(nameof(Login), [typeof(string), typeof(string)])]
[EnumerableMethodData(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. You may have experienced these, or you may have not even known about them.
Benchmark
Scenario: A single test that completes instantly
ubuntu-latest
BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 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 | 826.6 ms | 16.50 ms | 39.53 ms |
NUnit | 1,381.2 ms | 18.91 ms | 17.69 ms |
xUnit | 1,364.3 ms | 20.98 ms | 19.62 ms |
MSTest | 1,226.8 ms | 23.35 ms | 21.85 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 | 527.5 ms | 37.76 ms | 111.33 ms | 471.6 ms |
NUnit | 782.2 ms | 15.39 ms | 22.56 ms | 780.1 ms |
xUnit | 731.6 ms | 14.56 ms | 21.79 ms | 731.5 ms |
MSTest | 659.7 ms | 13.13 ms | 32.46 ms | 648.9 ms |
windows-latest
BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2655) (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 | 779.0 ms | 15.36 ms | 21.54 ms |
NUnit | 1,304.9 ms | 8.77 ms | 7.77 ms |
xUnit | 1,285.8 ms | 10.50 ms | 9.82 ms |
MSTest | 1,156.0 ms | 7.88 ms | 6.15 ms |
Scenario: A test that takes 50ms to execute, repeated 100 times
ubuntu-latest
BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 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 | 879.2 ms | 17.56 ms | 37.80 ms |
NUnit | 6,537.1 ms | 19.71 ms | 18.44 ms |
xUnit | 6,550.0 ms | 27.93 ms | 26.13 ms |
MSTest | 6,479.4 ms | 26.10 ms | 23.13 ms |
windows-latest
BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2655) (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 | 846.6 ms | 16.84 ms | 23.61 ms |
NUnit | 7,489.9 ms | 13.69 ms | 12.80 ms |
xUnit | 7,475.9 ms | 24.41 ms | 22.83 ms |
MSTest | 7,426.7 ms | 20.98 ms | 19.62 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 | 602.3 ms | 22.12 ms | 65.23 ms |
NUnit | 14,004.1 ms | 279.40 ms | 589.35 ms |
xUnit | 14,424.8 ms | 281.98 ms | 422.06 ms |
MSTest | 14,217.9 ms | 279.26 ms | 321.59 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 | 585 | 10/7/2024 | |
0.1.980 | 80 | 10/7/2024 | |
0.1.971 | 79 | 10/7/2024 | |
0.1.966 | 92 | 10/7/2024 | |
0.1.962 | 83 | 10/6/2024 | |
0.1.961 | 83 | 10/6/2024 | |
0.1.958 | 80 | 10/6/2024 | |
0.1.954 | 89 | 10/6/2024 | |
0.1.949 | 82 | 10/6/2024 | |
0.1.942 | 88 | 10/5/2024 | |
0.1.939 | 83 | 10/5/2024 | |
0.1.937 | 85 | 10/5/2024 | |
0.1.934 | 81 | 10/5/2024 | |
0.1.931 | 87 | 10/5/2024 | |
0.1.928 | 84 | 10/4/2024 | |
0.1.923 | 88 | 10/4/2024 | |
0.1.916 | 83 | 10/3/2024 | |
0.1.911 | 94 | 10/3/2024 | |
0.1.897 | 114 | 10/2/2024 | |
0.1.894 | 86 | 10/2/2024 | |
0.1.891 | 89 | 10/2/2024 | |
0.1.885 | 89 | 10/1/2024 | |
0.1.877 | 92 | 9/29/2024 | |
0.1.872 | 99 | 9/29/2024 | |
0.1.869 | 91 | 9/29/2024 | |
0.1.864 | 90 | 9/28/2024 | |
0.1.863 | 93 | 9/28/2024 | |
0.1.857 | 88 | 9/28/2024 | |
0.1.842 | 93 | 9/26/2024 | |
0.1.827 | 91 | 9/25/2024 | |
0.1.818 | 90 | 9/24/2024 | |
0.1.817 | 86 | 9/24/2024 | |
0.1.816 | 87 | 9/24/2024 | |
0.1.812 | 99 | 9/23/2024 | |
0.1.807 | 88 | 9/23/2024 | |
0.1.804 | 106 | 9/22/2024 | |
0.1.801 | 97 | 9/22/2024 | |
0.1.797 | 88 | 9/22/2024 | |
0.1.793 | 109 | 9/21/2024 | |
0.1.791 | 86 | 9/21/2024 | |
0.1.790 | 85 | 9/21/2024 | |
0.1.783 | 98 | 9/20/2024 | |
0.1.773 | 94 | 9/20/2024 | |
0.1.767 | 93 | 9/19/2024 | |
0.1.763 | 92 | 9/19/2024 | |
0.1.762 | 96 | 9/19/2024 | |
0.1.759 | 96 | 9/19/2024 | |
0.1.752 | 91 | 9/18/2024 | |
0.1.741 | 94 | 9/17/2024 | |
0.1.738 | 116 | 9/16/2024 | |
0.1.732 | 113 | 9/16/2024 | |
0.1.720 | 108 | 9/15/2024 | |
0.1.716 | 113 | 9/15/2024 | |
0.1.714 | 107 | 9/15/2024 | |
0.1.711 | 101 | 9/15/2024 | |
0.1.703 | 321 | 9/14/2024 | |
0.1.697 | 199 | 9/14/2024 | |
0.1.691 | 324 | 9/13/2024 | |
0.1.686 | 169 | 9/13/2024 | |
0.1.672 | 388 | 9/12/2024 | |
0.1.667 | 206 | 9/11/2024 | |
0.1.664 | 141 | 9/11/2024 | |
0.1.653 | 259 | 9/11/2024 | |
0.1.639 | 328 | 9/10/2024 | |
0.1.634 | 176 | 9/10/2024 | |
0.1.623 | 308 | 9/7/2024 | |
0.1.600 | 574 | 9/6/2024 | |
0.1.582 | 336 | 9/5/2024 | |
0.1.578 | 134 | 9/5/2024 | |
0.1.575 | 124 | 9/4/2024 | |
0.1.518 | 361 | 9/2/2024 | |
0.1.512 | 1,137 | 8/30/2024 | |
0.1.508 | 129 | 8/29/2024 | |
0.1.506 | 200 | 8/28/2024 | |
0.1.505 | 143 | 8/28/2024 | |
0.1.504 | 130 | 8/28/2024 | |
0.1.503 | 174 | 8/27/2024 | |
0.1.502 | 134 | 8/27/2024 | |
0.1.497 | 129 | 8/27/2024 | |
0.1.495 | 129 | 8/27/2024 | |
0.1.486 | 136 | 8/9/2024 | |
0.1.481 | 287 | 8/8/2024 | |
0.1.479 | 141 | 8/8/2024 | |
0.1.474 | 135 | 8/7/2024 | |
0.1.471 | 167 | 8/7/2024 | |
0.1.470 | 112 | 8/7/2024 | |
0.1.467 | 130 | 8/7/2024 | |
0.1.455 | 121 | 7/31/2024 | |
0.1.454 | 97 | 7/30/2024 |