TUnit.Assertions.Analyzers 0.1.711

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.711                
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.711                
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.711" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TUnit.Assertions.Analyzers --version 0.1.711                
#r "nuget: TUnit.Assertions.Analyzers, 0.1.711"                
#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.
// Install TUnit.Assertions.Analyzers as a Cake Addin
#addin nuget:?package=TUnit.Assertions.Analyzers&version=0.1.711

// Install TUnit.Assertions.Analyzers as a Cake Tool
#tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.711                

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: 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 82.37 ms 0.408 ms 0.319 ms
TUnit 418.20 ms 7.980 ms 7.837 ms
NUnit 687.86 ms 7.438 ms 6.594 ms
xUnit 679.71 ms 7.865 ms 6.568 ms
MSTest 615.39 ms 5.381 ms 5.034 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 83.20 ms 1.655 ms 2.984 ms 83.14 ms
TUnit 766.49 ms 15.173 ms 21.270 ms 779.13 ms
NUnit 1,295.60 ms 13.547 ms 12.672 ms 1,294.72 ms
xUnit 1,268.32 ms 4.511 ms 3.767 ms 1,269.34 ms
MSTest 1,157.17 ms 8.912 ms 7.900 ms 1,156.98 ms
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 46.10 ms 1.295 ms 3.817 ms
TUnit 807.52 ms 16.044 ms 35.884 ms
NUnit 1,386.41 ms 27.091 ms 26.607 ms
xUnit 1,366.56 ms 24.504 ms 21.722 ms
MSTest 1,247.83 ms 24.279 ms 28.903 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.83 ms 1.810 ms 4.406 ms
TUnit 904.44 ms 18.078 ms 35.683 ms
NUnit 6,606.79 ms 28.250 ms 26.425 ms
xUnit 6,580.08 ms 18.547 ms 15.487 ms
MSTest 6,559.48 ms 24.183 ms 22.621 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 150.3 ms 2.98 ms 6.49 ms
TUnit 863.5 ms 16.84 ms 24.14 ms
NUnit 7,542.6 ms 17.32 ms 16.20 ms
xUnit 7,523.6 ms 15.47 ms 14.47 ms
MSTest 7,474.1 ms 8.92 ms 7.91 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 255.1 ms 14.12 ms 41.18 ms
TUnit 608.3 ms 21.48 ms 63.33 ms
NUnit 14,051.1 ms 279.87 ms 558.94 ms
xUnit 14,313.0 ms 282.02 ms 536.57 ms
MSTest 14,476.6 ms 284.59 ms 527.51 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. 
.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 657 10/7/2024 0.1.984 is deprecated.
0.1.980 88 10/7/2024 0.1.980 is deprecated.
0.1.971 85 10/7/2024 0.1.971 is deprecated.
0.1.966 101 10/7/2024 0.1.966 is deprecated.
0.1.962 90 10/6/2024 0.1.962 is deprecated.
0.1.961 90 10/6/2024 0.1.961 is deprecated.
0.1.958 87 10/6/2024 0.1.958 is deprecated.
0.1.954 96 10/6/2024 0.1.954 is deprecated.
0.1.949 89 10/6/2024 0.1.949 is deprecated.
0.1.942 95 10/5/2024 0.1.942 is deprecated.
0.1.939 89 10/5/2024 0.1.939 is deprecated.
0.1.937 91 10/5/2024 0.1.937 is deprecated.
0.1.934 87 10/5/2024 0.1.934 is deprecated.
0.1.931 93 10/5/2024 0.1.931 is deprecated.
0.1.928 90 10/4/2024 0.1.928 is deprecated.
0.1.923 94 10/4/2024 0.1.923 is deprecated.
0.1.916 89 10/3/2024 0.1.916 is deprecated.
0.1.911 102 10/3/2024 0.1.911 is deprecated.
0.1.897 120 10/2/2024 0.1.897 is deprecated.
0.1.894 92 10/2/2024 0.1.894 is deprecated.
0.1.891 95 10/2/2024 0.1.891 is deprecated.
0.1.885 95 10/1/2024 0.1.885 is deprecated.
0.1.877 98 9/29/2024 0.1.877 is deprecated.
0.1.872 105 9/29/2024 0.1.872 is deprecated.
0.1.869 97 9/29/2024 0.1.869 is deprecated.
0.1.864 96 9/28/2024 0.1.864 is deprecated.
0.1.863 99 9/28/2024 0.1.863 is deprecated.
0.1.857 94 9/28/2024 0.1.857 is deprecated.
0.1.842 99 9/26/2024 0.1.842 is deprecated.
0.1.827 97 9/25/2024 0.1.827 is deprecated.
0.1.818 96 9/24/2024 0.1.818 is deprecated.
0.1.817 92 9/24/2024 0.1.817 is deprecated.
0.1.816 93 9/24/2024 0.1.816 is deprecated.
0.1.812 105 9/23/2024 0.1.812 is deprecated.
0.1.807 94 9/23/2024 0.1.807 is deprecated.
0.1.804 114 9/22/2024 0.1.804 is deprecated.
0.1.801 103 9/22/2024 0.1.801 is deprecated.
0.1.797 94 9/22/2024 0.1.797 is deprecated.
0.1.793 114 9/21/2024 0.1.793 is deprecated.
0.1.791 92 9/21/2024 0.1.791 is deprecated.
0.1.790 91 9/21/2024 0.1.790 is deprecated.
0.1.783 104 9/20/2024 0.1.783 is deprecated.
0.1.773 99 9/20/2024 0.1.773 is deprecated.
0.1.767 99 9/19/2024 0.1.767 is deprecated.
0.1.763 98 9/19/2024 0.1.763 is deprecated.
0.1.762 102 9/19/2024 0.1.762 is deprecated.
0.1.759 102 9/19/2024 0.1.759 is deprecated.
0.1.752 97 9/18/2024 0.1.752 is deprecated.
0.1.741 100 9/17/2024 0.1.741 is deprecated.
0.1.738 122 9/16/2024 0.1.738 is deprecated.
0.1.732 119 9/16/2024 0.1.732 is deprecated.
0.1.720 113 9/15/2024 0.1.720 is deprecated.
0.1.716 119 9/15/2024 0.1.716 is deprecated.
0.1.714 113 9/15/2024 0.1.714 is deprecated.
0.1.711 107 9/15/2024 0.1.711 is deprecated.
0.1.703 327 9/14/2024 0.1.703 is deprecated.
0.1.697 205 9/14/2024 0.1.697 is deprecated.
0.1.691 330 9/13/2024 0.1.691 is deprecated.
0.1.686 175 9/13/2024 0.1.686 is deprecated.
0.1.672 394 9/12/2024 0.1.672 is deprecated.
0.1.667 211 9/11/2024 0.1.667 is deprecated.
0.1.664 146 9/11/2024 0.1.664 is deprecated.
0.1.653 264 9/11/2024 0.1.653 is deprecated.
0.1.639 334 9/10/2024 0.1.639 is deprecated.
0.1.634 182 9/10/2024 0.1.634 is deprecated.
0.1.623 314 9/7/2024 0.1.623 is deprecated.
0.1.600 579 9/6/2024 0.1.600 is deprecated.
0.1.582 341 9/5/2024 0.1.582 is deprecated.
0.1.578 139 9/5/2024 0.1.578 is deprecated.
0.1.575 129 9/4/2024 0.1.575 is deprecated.
0.1.518 367 9/2/2024 0.1.518 is deprecated.
0.1.512 1,143 8/30/2024 0.1.512 is deprecated.
0.1.508 135 8/29/2024 0.1.508 is deprecated.
0.1.506 208 8/28/2024 0.1.506 is deprecated.
0.1.505 149 8/28/2024 0.1.505 is deprecated.
0.1.504 136 8/28/2024 0.1.504 is deprecated.
0.1.503 180 8/27/2024 0.1.503 is deprecated.
0.1.502 140 8/27/2024 0.1.502 is deprecated.
0.1.497 135 8/27/2024 0.1.497 is deprecated.
0.1.495 137 8/27/2024 0.1.495 is deprecated.
0.1.486 142 8/9/2024 0.1.486 is deprecated.
0.1.481 292 8/8/2024 0.1.481 is deprecated.
0.1.479 146 8/8/2024 0.1.479 is deprecated.
0.1.474 141 8/7/2024 0.1.474 is deprecated.
0.1.471 173 8/7/2024 0.1.471 is deprecated.
0.1.470 118 8/7/2024 0.1.470 is deprecated.
0.1.467 136 8/7/2024 0.1.467 is deprecated.
0.1.455 126 7/31/2024 0.1.455 is deprecated.
0.1.454 102 7/30/2024 0.1.454 is deprecated.