TUnit.Assertions.Analyzers 0.1.738

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.738
                    
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.738
                    
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.738" />
                    
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.738" />
                    
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.738
                    
#r "nuget: TUnit.Assertions.Analyzers, 0.1.738"
                    
#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.738
                    
#: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.738
                    
Install as a Cake Addin
#tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.738
                    
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. As of September 2024, IDEs do not fully support this testing platform yet.

Visual Studio 17.10 onwards 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 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

    [Test]
    public async Task Test1()
    {
        var value = "Hello world!";

        await Assert.That(value).IsNotNull()
                .And.IsEqualTo("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.

Read more here

Benchmark

Scenario: Building the test project

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
Build_TUnit 1.555 s 0.0296 s 0.0352 s
Build_NUnit 1.439 s 0.0269 s 0.0225 s
Build_xUnit 1.454 s 0.0280 s 0.0364 s
Build_MSTest 1.454 s 0.0276 s 0.0258 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
Build_TUnit 838.0 ms 16.71 ms 35.97 ms
Build_NUnit 725.6 ms 12.92 ms 12.08 ms
Build_xUnit 730.0 ms 12.02 ms 11.24 ms
Build_MSTest 964.8 ms 26.88 ms 78.83 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.411 s 0.0274 s 0.0316 s
Build_NUnit 1.285 s 0.0145 s 0.0135 s
Build_xUnit 1.307 s 0.0186 s 0.0174 s
Build_MSTest 1.323 s 0.0185 s 0.0173 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.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_AOT 47.36 ms 0.941 ms 2.217 ms
TUnit 774.86 ms 15.442 ms 28.237 ms
NUnit 1,353.03 ms 20.251 ms 17.952 ms
xUnit 1,355.48 ms 21.155 ms 19.789 ms
MSTest 1,218.13 ms 12.264 ms 11.472 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 77.74 ms 1.303 ms 1.018 ms
TUnit 741.50 ms 14.511 ms 19.371 ms
NUnit 1,285.39 ms 10.128 ms 9.474 ms
xUnit 1,263.86 ms 10.334 ms 9.666 ms
MSTest 1,142.96 ms 4.846 ms 4.295 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 111.9 ms 8.76 ms 25.69 ms 106.0 ms
TUnit 562.7 ms 25.75 ms 73.47 ms 535.4 ms
NUnit 729.2 ms 18.53 ms 52.28 ms 701.1 ms
xUnit 687.3 ms 13.38 ms 12.51 ms 684.5 ms
MSTest 810.4 ms 26.48 ms 78.07 ms 828.5 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.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_AOT 90.98 ms 1.846 ms 5.444 ms
TUnit 856.79 ms 17.134 ms 29.095 ms
NUnit 6,551.98 ms 18.653 ms 17.448 ms
xUnit 6,549.25 ms 20.845 ms 19.498 ms
MSTest 6,519.74 ms 35.108 ms 32.840 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 133.8 ms 2.67 ms 6.55 ms
TUnit 809.5 ms 15.65 ms 18.63 ms
NUnit 7,472.4 ms 11.88 ms 11.11 ms
xUnit 7,460.1 ms 18.25 ms 16.17 ms
MSTest 7,423.7 ms 11.34 ms 10.61 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 266.3 ms 19.28 ms 56.86 ms
TUnit 629.3 ms 21.49 ms 62.69 ms
NUnit 14,284.0 ms 281.47 ms 548.99 ms
xUnit 14,398.3 ms 287.71 ms 594.17 ms
MSTest 14,535.3 ms 286.80 ms 592.29 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,049 10/7/2024 0.1.984 is deprecated.
0.1.980 148 10/7/2024 0.1.980 is deprecated.
0.1.971 151 10/7/2024 0.1.971 is deprecated.
0.1.966 152 10/7/2024 0.1.966 is deprecated.
0.1.962 149 10/6/2024 0.1.962 is deprecated.
0.1.961 152 10/6/2024 0.1.961 is deprecated.
0.1.958 145 10/6/2024 0.1.958 is deprecated.
0.1.954 154 10/6/2024 0.1.954 is deprecated.
0.1.949 146 10/6/2024 0.1.949 is deprecated.
0.1.942 161 10/5/2024 0.1.942 is deprecated.
0.1.939 157 10/5/2024 0.1.939 is deprecated.
0.1.937 152 10/5/2024 0.1.937 is deprecated.
0.1.934 138 10/5/2024 0.1.934 is deprecated.
0.1.931 151 10/5/2024 0.1.931 is deprecated.
0.1.928 153 10/4/2024 0.1.928 is deprecated.
0.1.923 152 10/4/2024 0.1.923 is deprecated.
0.1.916 147 10/3/2024 0.1.916 is deprecated.
0.1.911 165 10/3/2024 0.1.911 is deprecated.
0.1.897 181 10/2/2024 0.1.897 is deprecated.
0.1.894 143 10/2/2024 0.1.894 is deprecated.
0.1.891 148 10/2/2024 0.1.891 is deprecated.
0.1.885 151 10/1/2024 0.1.885 is deprecated.
0.1.877 158 9/29/2024 0.1.877 is deprecated.
0.1.872 158 9/29/2024 0.1.872 is deprecated.
0.1.869 159 9/29/2024 0.1.869 is deprecated.
0.1.864 161 9/28/2024 0.1.864 is deprecated.
0.1.863 168 9/28/2024 0.1.863 is deprecated.
0.1.857 151 9/28/2024 0.1.857 is deprecated.
0.1.842 164 9/26/2024 0.1.842 is deprecated.
0.1.827 150 9/25/2024 0.1.827 is deprecated.
0.1.818 149 9/24/2024 0.1.818 is deprecated.
0.1.817 146 9/24/2024 0.1.817 is deprecated.
0.1.816 147 9/24/2024 0.1.816 is deprecated.
0.1.812 153 9/23/2024 0.1.812 is deprecated.
0.1.807 149 9/23/2024 0.1.807 is deprecated.
0.1.804 170 9/22/2024 0.1.804 is deprecated.
0.1.801 159 9/22/2024 0.1.801 is deprecated.
0.1.797 153 9/22/2024 0.1.797 is deprecated.
0.1.793 173 9/21/2024 0.1.793 is deprecated.
0.1.791 149 9/21/2024 0.1.791 is deprecated.
0.1.790 143 9/21/2024 0.1.790 is deprecated.
0.1.783 157 9/20/2024 0.1.783 is deprecated.
0.1.773 150 9/20/2024 0.1.773 is deprecated.
0.1.767 150 9/19/2024 0.1.767 is deprecated.
0.1.763 149 9/19/2024 0.1.763 is deprecated.
0.1.762 150 9/19/2024 0.1.762 is deprecated.
0.1.759 152 9/19/2024 0.1.759 is deprecated.
0.1.752 154 9/18/2024 0.1.752 is deprecated.
0.1.741 153 9/17/2024 0.1.741 is deprecated.
0.1.738 178 9/16/2024 0.1.738 is deprecated.
0.1.732 169 9/16/2024 0.1.732 is deprecated.
0.1.720 169 9/15/2024 0.1.720 is deprecated.
0.1.716 179 9/15/2024 0.1.716 is deprecated.
0.1.714 160 9/15/2024 0.1.714 is deprecated.
0.1.711 157 9/15/2024 0.1.711 is deprecated.
0.1.703 382 9/14/2024 0.1.703 is deprecated.
0.1.697 284 9/14/2024 0.1.697 is deprecated.
0.1.691 382 9/13/2024 0.1.691 is deprecated.
0.1.686 224 9/13/2024 0.1.686 is deprecated.
0.1.672 450 9/12/2024 0.1.672 is deprecated.
0.1.667 257 9/11/2024 0.1.667 is deprecated.
0.1.664 195 9/11/2024 0.1.664 is deprecated.
0.1.653 323 9/11/2024 0.1.653 is deprecated.
0.1.639 380 9/10/2024 0.1.639 is deprecated.
0.1.634 231 9/10/2024 0.1.634 is deprecated.
0.1.623 366 9/7/2024 0.1.623 is deprecated.
0.1.600 637 9/6/2024 0.1.600 is deprecated.
0.1.582 397 9/5/2024 0.1.582 is deprecated.
0.1.578 198 9/5/2024 0.1.578 is deprecated.
0.1.575 173 9/4/2024 0.1.575 is deprecated.
0.1.518 419 9/2/2024 0.1.518 is deprecated.
0.1.512 1,204 8/30/2024 0.1.512 is deprecated.
0.1.508 189 8/29/2024 0.1.508 is deprecated.
0.1.506 256 8/28/2024 0.1.506 is deprecated.
0.1.505 200 8/28/2024 0.1.505 is deprecated.
0.1.504 180 8/28/2024 0.1.504 is deprecated.
0.1.503 226 8/27/2024 0.1.503 is deprecated.
0.1.502 199 8/27/2024 0.1.502 is deprecated.
0.1.497 182 8/27/2024 0.1.497 is deprecated.
0.1.495 197 8/27/2024 0.1.495 is deprecated.
0.1.486 190 8/9/2024 0.1.486 is deprecated.
0.1.481 355 8/8/2024 0.1.481 is deprecated.
0.1.479 191 8/8/2024 0.1.479 is deprecated.
0.1.474 183 8/7/2024 0.1.474 is deprecated.
0.1.471 218 8/7/2024 0.1.471 is deprecated.
0.1.470 168 8/7/2024 0.1.470 is deprecated.
0.1.467 177 8/7/2024 0.1.467 is deprecated.
0.1.455 161 7/31/2024 0.1.455 is deprecated.
0.1.454 152 7/30/2024 0.1.454 is deprecated.