TUnit.Assertions.Analyzers 0.1.807

Prefix Reserved
Suggested Alternatives

TUnit.Assertions

Additional Details

TUnit.Assertions handles analyzing natively now.

There is a newer version of this package available.
See the version list below for details.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.807
                    
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.807
                    
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="TUnit.Assertions.Analyzers" Version="0.1.807" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TUnit.Assertions.Analyzers" Version="0.1.807" />
                    
Directory.Packages.props
<PackageReference Include="TUnit.Assertions.Analyzers" />
                    
Project file
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 TUnit.Assertions.Analyzers --version 0.1.807
                    
#r "nuget: TUnit.Assertions.Analyzers, 0.1.807"
                    
#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 TUnit.Assertions.Analyzers@0.1.807
                    
#: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=TUnit.Assertions.Analyzers&version=0.1.807
                    
Install as a Cake Addin
#tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.807
                    
Install as a Cake Tool

TUnit

A modern, flexible and fast testing framework for .NET 8 and up. With Native AOT and Trimmed Single File application support included!

nuget Nuget GitHub Workflow Status (with event) GitHub last commit (branch) License

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
  • 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.

Read more here

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 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 871.7 ms 24.65 ms 67.88 ms 847.7 ms
Build_NUnit 762.5 ms 15.10 ms 35.89 ms 754.0 ms
Build_xUnit 745.4 ms 13.08 ms 21.13 ms 746.1 ms
Build_MSTest 797.9 ms 14.65 ms 25.27 ms 791.4 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 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.537 s 0.0289 s 0.0256 s
Build_NUnit 1.415 s 0.0228 s 0.0213 s
Build_xUnit 1.425 s 0.0194 s 0.0172 s
Build_MSTest 1.451 s 0.0250 s 0.0234 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 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.545 s 0.0261 s 0.0244 s
Build_NUnit 1.422 s 0.0207 s 0.0173 s
Build_xUnit 1.421 s 0.0282 s 0.0302 s
Build_MSTest 1.429 s 0.0273 s 0.0280 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 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 106.9 ms 6.29 ms 18.45 ms
TUnit 555.1 ms 11.84 ms 33.02 ms
NUnit 965.3 ms 19.28 ms 36.68 ms
xUnit 948.3 ms 18.73 ms 33.78 ms
MSTest 867.3 ms 16.75 ms 24.56 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 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 46.27 ms 0.916 ms 2.509 ms
TUnit 751.80 ms 15.022 ms 23.826 ms
NUnit 1,314.42 ms 22.592 ms 21.133 ms
xUnit 1,283.48 ms 8.884 ms 7.875 ms
MSTest 1,168.82 ms 13.663 ms 12.781 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 88.41 ms 1.758 ms 4.212 ms
TUnit 806.88 ms 15.981 ms 23.424 ms
NUnit 1,409.61 ms 27.005 ms 28.895 ms
xUnit 1,392.76 ms 26.886 ms 26.406 ms
MSTest 1,283.80 ms 25.589 ms 30.462 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 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 226.6 ms 18.29 ms 53.94 ms
TUnit 655.3 ms 19.43 ms 57.28 ms
NUnit 14,123.5 ms 269.66 ms 532.28 ms
xUnit 14,311.9 ms 283.56 ms 511.32 ms
MSTest 14,494.1 ms 281.36 ms 470.09 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 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 80.98 ms 1.612 ms 2.648 ms
TUnit 844.56 ms 16.007 ms 19.657 ms
NUnit 6,351.73 ms 21.875 ms 20.462 ms
xUnit 6,457.82 ms 17.650 ms 16.509 ms
MSTest 6,347.86 ms 17.943 ms 16.784 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 Median
TUnit_AOT 136.1 ms 2.70 ms 7.34 ms 140.3 ms
TUnit 830.0 ms 16.21 ms 22.72 ms 841.7 ms
NUnit 8,843.2 ms 32.27 ms 30.18 ms 8,844.3 ms
xUnit 8,777.0 ms 174.62 ms 220.84 ms 8,817.7 ms
MSTest 8,803.7 ms 32.91 ms 30.79 ms 8,794.3 ms
Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 1,025 10/7/2024 0.1.984 is deprecated.
0.1.980 137 10/7/2024 0.1.980 is deprecated.
0.1.971 133 10/7/2024 0.1.971 is deprecated.
0.1.966 140 10/7/2024 0.1.966 is deprecated.
0.1.962 138 10/6/2024 0.1.962 is deprecated.
0.1.961 135 10/6/2024 0.1.961 is deprecated.
0.1.958 136 10/6/2024 0.1.958 is deprecated.
0.1.954 143 10/6/2024 0.1.954 is deprecated.
0.1.949 134 10/6/2024 0.1.949 is deprecated.
0.1.942 142 10/5/2024 0.1.942 is deprecated.
0.1.939 142 10/5/2024 0.1.939 is deprecated.
0.1.937 138 10/5/2024 0.1.937 is deprecated.
0.1.934 127 10/5/2024 0.1.934 is deprecated.
0.1.931 140 10/5/2024 0.1.931 is deprecated.
0.1.928 141 10/4/2024 0.1.928 is deprecated.
0.1.923 139 10/4/2024 0.1.923 is deprecated.
0.1.916 138 10/3/2024 0.1.916 is deprecated.
0.1.911 154 10/3/2024 0.1.911 is deprecated.
0.1.897 172 10/2/2024 0.1.897 is deprecated.
0.1.894 134 10/2/2024 0.1.894 is deprecated.
0.1.891 139 10/2/2024 0.1.891 is deprecated.
0.1.885 140 10/1/2024 0.1.885 is deprecated.
0.1.877 148 9/29/2024 0.1.877 is deprecated.
0.1.872 148 9/29/2024 0.1.872 is deprecated.
0.1.869 145 9/29/2024 0.1.869 is deprecated.
0.1.864 143 9/28/2024 0.1.864 is deprecated.
0.1.863 145 9/28/2024 0.1.863 is deprecated.
0.1.857 141 9/28/2024 0.1.857 is deprecated.
0.1.842 149 9/26/2024 0.1.842 is deprecated.
0.1.827 139 9/25/2024 0.1.827 is deprecated.
0.1.818 139 9/24/2024 0.1.818 is deprecated.
0.1.817 134 9/24/2024 0.1.817 is deprecated.
0.1.816 136 9/24/2024 0.1.816 is deprecated.
0.1.812 142 9/23/2024 0.1.812 is deprecated.
0.1.807 139 9/23/2024 0.1.807 is deprecated.
0.1.804 159 9/22/2024 0.1.804 is deprecated.
0.1.801 147 9/22/2024 0.1.801 is deprecated.
0.1.797 140 9/22/2024 0.1.797 is deprecated.
0.1.793 161 9/21/2024 0.1.793 is deprecated.
0.1.791 139 9/21/2024 0.1.791 is deprecated.
0.1.790 131 9/21/2024 0.1.790 is deprecated.
0.1.783 147 9/20/2024 0.1.783 is deprecated.
0.1.773 138 9/20/2024 0.1.773 is deprecated.
0.1.767 140 9/19/2024 0.1.767 is deprecated.
0.1.763 137 9/19/2024 0.1.763 is deprecated.
0.1.762 139 9/19/2024 0.1.762 is deprecated.
0.1.759 142 9/19/2024 0.1.759 is deprecated.
0.1.752 142 9/18/2024 0.1.752 is deprecated.
0.1.741 140 9/17/2024 0.1.741 is deprecated.
0.1.738 168 9/16/2024 0.1.738 is deprecated.
0.1.732 157 9/16/2024 0.1.732 is deprecated.
0.1.720 159 9/15/2024 0.1.720 is deprecated.
0.1.716 166 9/15/2024 0.1.716 is deprecated.
0.1.714 151 9/15/2024 0.1.714 is deprecated.
0.1.711 146 9/15/2024 0.1.711 is deprecated.
0.1.703 372 9/14/2024 0.1.703 is deprecated.
0.1.697 273 9/14/2024 0.1.697 is deprecated.
0.1.691 372 9/13/2024 0.1.691 is deprecated.
0.1.686 214 9/13/2024 0.1.686 is deprecated.
0.1.672 441 9/12/2024 0.1.672 is deprecated.
0.1.667 245 9/11/2024 0.1.667 is deprecated.
0.1.664 185 9/11/2024 0.1.664 is deprecated.
0.1.653 304 9/11/2024 0.1.653 is deprecated.
0.1.639 371 9/10/2024 0.1.639 is deprecated.
0.1.634 222 9/10/2024 0.1.634 is deprecated.
0.1.623 356 9/7/2024 0.1.623 is deprecated.
0.1.600 621 9/6/2024 0.1.600 is deprecated.
0.1.582 381 9/5/2024 0.1.582 is deprecated.
0.1.578 180 9/5/2024 0.1.578 is deprecated.
0.1.575 163 9/4/2024 0.1.575 is deprecated.
0.1.518 407 9/2/2024 0.1.518 is deprecated.
0.1.512 1,194 8/30/2024 0.1.512 is deprecated.
0.1.508 179 8/29/2024 0.1.508 is deprecated.
0.1.506 246 8/28/2024 0.1.506 is deprecated.
0.1.505 188 8/28/2024 0.1.505 is deprecated.
0.1.504 170 8/28/2024 0.1.504 is deprecated.
0.1.503 215 8/27/2024 0.1.503 is deprecated.
0.1.502 182 8/27/2024 0.1.502 is deprecated.
0.1.497 171 8/27/2024 0.1.497 is deprecated.
0.1.495 186 8/27/2024 0.1.495 is deprecated.
0.1.486 178 8/9/2024 0.1.486 is deprecated.
0.1.481 337 8/8/2024 0.1.481 is deprecated.
0.1.479 181 8/8/2024 0.1.479 is deprecated.
0.1.474 174 8/7/2024 0.1.474 is deprecated.
0.1.471 206 8/7/2024 0.1.471 is deprecated.
0.1.470 157 8/7/2024 0.1.470 is deprecated.
0.1.467 168 8/7/2024 0.1.467 is deprecated.
0.1.455 151 7/31/2024 0.1.455 is deprecated.
0.1.454 137 7/30/2024 0.1.454 is deprecated.