TUnit.Assertions.Analyzers
0.1.877
Prefix Reserved
TUnit.Assertions handles analyzing natively now.
See the version list below for details.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.877
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.877
<PackageReference Include="TUnit.Assertions.Analyzers" Version="0.1.877" />
paket add TUnit.Assertions.Analyzers --version 0.1.877
#r "nuget: TUnit.Assertions.Analyzers, 0.1.877"
// Install TUnit.Assertions.Analyzers as a Cake Addin #addin nuget:?package=TUnit.Assertions.Analyzers&version=0.1.877 // Install TUnit.Assertions.Analyzers as a Cake Tool #tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.877
TUnit
A modern, flexible and fast testing framework for .NET 8 and up. With Native AOT and Trimmed Single File application support included!
TUnit is designed to aid with all testing types:
- Unit
- Integration
- Acceptance
- and more!
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 on the Preview version currently.
- Install the latest preview version
- Open Visual Studio and go to Tools > Manage Preview Features
- Enable "Use testing platform server mode"
<img src="/docs/static/img/visual-studio.png" height="300px">
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
- Tests can depend on other tests to form chains, useful for if one test depends on state from another action. While not recommended for unit tests, this can be useful in integration testing where state matters
- Easy to read assertions - though you're also free to use whichever assertion library you like
- 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.
Prerelease
You'll notice that version 1.0 isn't out yet. While this framework is mostly feature complete, I'm waiting for a few things:
- Full Rider support for all features
- Full VS support for all features
- Open to feedback on existing features
- Open to ideas on new features
As such, the API may change. I'll try to limit this but it's a possibility.
Benchmark
Scenario: Building the test project
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), Arm64 RyuJIT AdvSIMD
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 870.8 ms | 17.39 ms | 27.08 ms |
Build_NUnit | 801.5 ms | 14.97 ms | 14.70 ms |
Build_xUnit | 802.1 ms | 12.81 ms | 11.98 ms |
Build_MSTest | 825.3 ms | 16.47 ms | 18.97 ms |
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.587 s | 0.0282 s | 0.0264 s |
Build_NUnit | 1.476 s | 0.0154 s | 0.0144 s |
Build_xUnit | 1.474 s | 0.0155 s | 0.0130 s |
Build_MSTest | 1.553 s | 0.0278 s | 0.0260 s |
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
Build_TUnit | 1.771 s | 0.0228 s | 0.0213 s |
Build_NUnit | 1.630 s | 0.0226 s | 0.0211 s |
Build_xUnit | 1.623 s | 0.0259 s | 0.0242 s |
Build_MSTest | 1.630 s | 0.0213 s | 0.0189 s |
Scenario: A single test that completes instantly (including spawning a new process and initialising the test framework)
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), Arm64 RyuJIT AdvSIMD
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 74.79 ms | 0.236 ms | 0.209 ms |
TUnit | 419.57 ms | 2.774 ms | 2.165 ms |
NUnit | 693.91 ms | 7.458 ms | 6.977 ms |
xUnit | 690.97 ms | 10.687 ms | 8.924 ms |
MSTest | 626.43 ms | 9.813 ms | 9.179 ms |
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 46.98 ms | 0.935 ms | 1.972 ms |
TUnit | 747.52 ms | 14.794 ms | 14.530 ms |
NUnit | 1,309.09 ms | 8.450 ms | 7.490 ms |
xUnit | 1,330.04 ms | 25.309 ms | 24.856 ms |
MSTest | 1,169.59 ms | 9.942 ms | 9.300 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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 77.66 ms | 1.467 ms | 1.372 ms |
TUnit | 758.40 ms | 15.142 ms | 24.017 ms |
NUnit | 1,319.30 ms | 12.351 ms | 11.553 ms |
xUnit | 1,308.72 ms | 10.872 ms | 9.078 ms |
MSTest | 1,204.04 ms | 16.655 ms | 15.579 ms |
Scenario: A test that takes 50ms to execute, repeated 100 times (including spawning a new process and initialising the test framework)
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), Arm64 RyuJIT AdvSIMD
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), Arm64 RyuJIT AdvSIMD
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 237.4 ms | 11.57 ms | 33.94 ms |
TUnit | 570.3 ms | 22.99 ms | 67.79 ms |
NUnit | 14,006.1 ms | 279.01 ms | 530.85 ms |
xUnit | 14,354.6 ms | 284.60 ms | 548.32 ms |
MSTest | 14,590.4 ms | 290.57 ms | 322.97 ms |
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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 82.99 ms | 1.672 ms | 4.931 ms |
TUnit | 815.43 ms | 14.295 ms | 18.588 ms |
NUnit | 6,323.96 ms | 18.078 ms | 16.910 ms |
xUnit | 6,424.87 ms | 22.637 ms | 21.174 ms |
MSTest | 6,373.45 ms | 29.581 ms | 27.670 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 9.0.100-rc.1.24452.12
[Host] : .NET 9.0.0 (9.0.24.43107), X64 RyuJIT AVX2
.NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
Method | Mean | Error | StdDev |
---|---|---|---|
TUnit_AOT | 130.7 ms | 2.68 ms | 7.91 ms |
TUnit | 833.0 ms | 16.65 ms | 22.22 ms |
NUnit | 7,554.6 ms | 28.66 ms | 26.81 ms |
xUnit | 7,516.7 ms | 21.16 ms | 19.79 ms |
MSTest | 7,496.9 ms | 19.95 ms | 18.66 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 | 606 | 10/7/2024 | |
0.1.980 | 84 | 10/7/2024 | |
0.1.971 | 81 | 10/7/2024 | |
0.1.966 | 97 | 10/7/2024 | |
0.1.962 | 86 | 10/6/2024 | |
0.1.961 | 85 | 10/6/2024 | |
0.1.958 | 82 | 10/6/2024 | |
0.1.954 | 91 | 10/6/2024 | |
0.1.949 | 84 | 10/6/2024 | |
0.1.942 | 90 | 10/5/2024 | |
0.1.939 | 85 | 10/5/2024 | |
0.1.937 | 87 | 10/5/2024 | |
0.1.934 | 83 | 10/5/2024 | |
0.1.931 | 89 | 10/5/2024 | |
0.1.928 | 86 | 10/4/2024 | |
0.1.923 | 90 | 10/4/2024 | |
0.1.916 | 85 | 10/3/2024 | |
0.1.911 | 98 | 10/3/2024 | |
0.1.897 | 116 | 10/2/2024 | |
0.1.894 | 88 | 10/2/2024 | |
0.1.891 | 91 | 10/2/2024 | |
0.1.885 | 91 | 10/1/2024 | |
0.1.877 | 94 | 9/29/2024 | |
0.1.872 | 101 | 9/29/2024 | |
0.1.869 | 93 | 9/29/2024 | |
0.1.864 | 92 | 9/28/2024 | |
0.1.863 | 95 | 9/28/2024 | |
0.1.857 | 90 | 9/28/2024 | |
0.1.842 | 95 | 9/26/2024 | |
0.1.827 | 93 | 9/25/2024 | |
0.1.818 | 92 | 9/24/2024 | |
0.1.817 | 88 | 9/24/2024 | |
0.1.816 | 89 | 9/24/2024 | |
0.1.812 | 101 | 9/23/2024 | |
0.1.807 | 90 | 9/23/2024 | |
0.1.804 | 110 | 9/22/2024 | |
0.1.801 | 99 | 9/22/2024 | |
0.1.797 | 90 | 9/22/2024 | |
0.1.793 | 110 | 9/21/2024 | |
0.1.791 | 88 | 9/21/2024 | |
0.1.790 | 87 | 9/21/2024 | |
0.1.783 | 100 | 9/20/2024 | |
0.1.773 | 95 | 9/20/2024 | |
0.1.767 | 95 | 9/19/2024 | |
0.1.763 | 94 | 9/19/2024 | |
0.1.762 | 98 | 9/19/2024 | |
0.1.759 | 98 | 9/19/2024 | |
0.1.752 | 93 | 9/18/2024 | |
0.1.741 | 96 | 9/17/2024 | |
0.1.738 | 118 | 9/16/2024 | |
0.1.732 | 115 | 9/16/2024 | |
0.1.720 | 109 | 9/15/2024 | |
0.1.716 | 115 | 9/15/2024 | |
0.1.714 | 109 | 9/15/2024 | |
0.1.711 | 103 | 9/15/2024 | |
0.1.703 | 323 | 9/14/2024 | |
0.1.697 | 201 | 9/14/2024 | |
0.1.691 | 326 | 9/13/2024 | |
0.1.686 | 171 | 9/13/2024 | |
0.1.672 | 390 | 9/12/2024 | |
0.1.667 | 207 | 9/11/2024 | |
0.1.664 | 142 | 9/11/2024 | |
0.1.653 | 260 | 9/11/2024 | |
0.1.639 | 330 | 9/10/2024 | |
0.1.634 | 178 | 9/10/2024 | |
0.1.623 | 310 | 9/7/2024 | |
0.1.600 | 575 | 9/6/2024 | |
0.1.582 | 337 | 9/5/2024 | |
0.1.578 | 135 | 9/5/2024 | |
0.1.575 | 125 | 9/4/2024 | |
0.1.518 | 363 | 9/2/2024 | |
0.1.512 | 1,139 | 8/30/2024 | |
0.1.508 | 131 | 8/29/2024 | |
0.1.506 | 202 | 8/28/2024 | |
0.1.505 | 145 | 8/28/2024 | |
0.1.504 | 132 | 8/28/2024 | |
0.1.503 | 176 | 8/27/2024 | |
0.1.502 | 136 | 8/27/2024 | |
0.1.497 | 131 | 8/27/2024 | |
0.1.495 | 133 | 8/27/2024 | |
0.1.486 | 138 | 8/9/2024 | |
0.1.481 | 288 | 8/8/2024 | |
0.1.479 | 142 | 8/8/2024 | |
0.1.474 | 137 | 8/7/2024 | |
0.1.471 | 169 | 8/7/2024 | |
0.1.470 | 114 | 8/7/2024 | |
0.1.467 | 132 | 8/7/2024 | |
0.1.455 | 122 | 7/31/2024 | |
0.1.454 | 98 | 7/30/2024 |