TUnit.Assertions.Analyzers 0.1.949

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.949                
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.949                
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.949" />                
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.949                
#r "nuget: TUnit.Assertions.Analyzers, 0.1.949"                
#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.949

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

TUnit

<a href="https://trendshift.io/repositories/11781" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11781" alt="thomhurst%2FTUnit | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>

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!

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
  • Property injection
  • 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
  • Dependency injection support (See here)
  • 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

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 868.8 ms 17.12 ms 30.43 ms
Build_NUnit 795.5 ms 15.33 ms 14.34 ms
Build_xUnit 827.5 ms 16.45 ms 30.08 ms
Build_MSTest 844.2 ms 16.06 ms 15.77 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.678 s 0.0318 s 0.0298 s
Build_NUnit 1.524 s 0.0208 s 0.0194 s
Build_xUnit 1.498 s 0.0136 s 0.0120 s
Build_MSTest 1.545 s 0.0201 s 0.0157 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.693 s 0.0282 s 0.0335 s
Build_NUnit 1.556 s 0.0200 s 0.0187 s
Build_xUnit 1.552 s 0.0125 s 0.0111 s
Build_MSTest 1.591 s 0.0138 s 0.0129 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 68.79 ms 0.472 ms 0.419 ms
TUnit 448.28 ms 8.909 ms 21.517 ms
NUnit 704.61 ms 9.085 ms 8.054 ms
xUnit 695.40 ms 9.755 ms 9.125 ms
MSTest 634.07 ms 7.656 ms 6.787 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 32.36 ms 1.457 ms 4.273 ms
TUnit 765.89 ms 15.084 ms 16.766 ms
NUnit 1,328.93 ms 12.494 ms 11.687 ms
xUnit 1,305.58 ms 13.347 ms 12.484 ms
MSTest 1,178.37 ms 11.697 ms 10.941 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 78.30 ms 1.119 ms 0.934 ms
TUnit 770.22 ms 14.951 ms 20.465 ms
NUnit 1,318.88 ms 15.868 ms 14.843 ms
xUnit 1,297.46 ms 14.023 ms 12.431 ms
MSTest 1,178.88 ms 15.484 ms 14.484 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 246.6 ms 11.15 ms 32.87 ms
TUnit 639.7 ms 19.07 ms 56.23 ms
NUnit 14,225.4 ms 282.62 ms 608.37 ms
xUnit 14,483.1 ms 287.39 ms 495.74 ms
MSTest 14,387.6 ms 285.26 ms 476.60 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 96.45 ms 1.903 ms 2.337 ms
TUnit 858.55 ms 16.972 ms 22.657 ms
NUnit 6,367.76 ms 10.731 ms 10.037 ms
xUnit 6,441.46 ms 20.628 ms 19.295 ms
MSTest 6,348.51 ms 23.980 ms 22.431 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 139.4 ms 2.66 ms 2.62 ms
TUnit 840.0 ms 16.68 ms 25.48 ms
NUnit 7,531.2 ms 17.80 ms 16.65 ms
xUnit 7,512.2 ms 17.82 ms 16.67 ms
MSTest 7,478.1 ms 16.39 ms 15.33 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 819 10/7/2024 0.1.984 is deprecated.
0.1.980 97 10/7/2024 0.1.980 is deprecated.
0.1.971 94 10/7/2024 0.1.971 is deprecated.
0.1.966 110 10/7/2024 0.1.966 is deprecated.
0.1.962 101 10/6/2024 0.1.962 is deprecated.
0.1.961 101 10/6/2024 0.1.961 is deprecated.
0.1.958 97 10/6/2024 0.1.958 is deprecated.
0.1.954 109 10/6/2024 0.1.954 is deprecated.
0.1.949 96 10/6/2024 0.1.949 is deprecated.
0.1.942 104 10/5/2024 0.1.942 is deprecated.
0.1.939 99 10/5/2024 0.1.939 is deprecated.
0.1.937 99 10/5/2024 0.1.937 is deprecated.
0.1.934 95 10/5/2024 0.1.934 is deprecated.
0.1.931 101 10/5/2024 0.1.931 is deprecated.
0.1.928 102 10/4/2024 0.1.928 is deprecated.
0.1.923 102 10/4/2024 0.1.923 is deprecated.
0.1.916 99 10/3/2024 0.1.916 is deprecated.
0.1.911 110 10/3/2024 0.1.911 is deprecated.
0.1.897 128 10/2/2024 0.1.897 is deprecated.
0.1.894 100 10/2/2024 0.1.894 is deprecated.
0.1.891 102 10/2/2024 0.1.891 is deprecated.
0.1.885 104 10/1/2024 0.1.885 is deprecated.
0.1.877 107 9/29/2024 0.1.877 is deprecated.
0.1.872 114 9/29/2024 0.1.872 is deprecated.
0.1.869 108 9/29/2024 0.1.869 is deprecated.
0.1.864 103 9/28/2024 0.1.864 is deprecated.
0.1.863 108 9/28/2024 0.1.863 is deprecated.
0.1.857 101 9/28/2024 0.1.857 is deprecated.
0.1.842 108 9/26/2024 0.1.842 is deprecated.
0.1.827 106 9/25/2024 0.1.827 is deprecated.
0.1.818 103 9/24/2024 0.1.818 is deprecated.
0.1.817 101 9/24/2024 0.1.817 is deprecated.
0.1.816 100 9/24/2024 0.1.816 is deprecated.
0.1.812 112 9/23/2024 0.1.812 is deprecated.
0.1.807 101 9/23/2024 0.1.807 is deprecated.
0.1.804 123 9/22/2024 0.1.804 is deprecated.
0.1.801 112 9/22/2024 0.1.801 is deprecated.
0.1.797 101 9/22/2024 0.1.797 is deprecated.
0.1.793 121 9/21/2024 0.1.793 is deprecated.
0.1.791 99 9/21/2024 0.1.791 is deprecated.
0.1.790 98 9/21/2024 0.1.790 is deprecated.
0.1.783 111 9/20/2024 0.1.783 is deprecated.
0.1.773 108 9/20/2024 0.1.773 is deprecated.
0.1.767 106 9/19/2024 0.1.767 is deprecated.
0.1.763 105 9/19/2024 0.1.763 is deprecated.
0.1.762 109 9/19/2024 0.1.762 is deprecated.
0.1.759 109 9/19/2024 0.1.759 is deprecated.
0.1.752 104 9/18/2024 0.1.752 is deprecated.
0.1.741 107 9/17/2024 0.1.741 is deprecated.
0.1.738 129 9/16/2024 0.1.738 is deprecated.
0.1.732 126 9/16/2024 0.1.732 is deprecated.
0.1.720 126 9/15/2024 0.1.720 is deprecated.
0.1.716 128 9/15/2024 0.1.716 is deprecated.
0.1.714 120 9/15/2024 0.1.714 is deprecated.
0.1.711 116 9/15/2024 0.1.711 is deprecated.
0.1.703 336 9/14/2024 0.1.703 is deprecated.
0.1.697 214 9/14/2024 0.1.697 is deprecated.
0.1.691 339 9/13/2024 0.1.691 is deprecated.
0.1.686 184 9/13/2024 0.1.686 is deprecated.
0.1.672 403 9/12/2024 0.1.672 is deprecated.
0.1.667 220 9/11/2024 0.1.667 is deprecated.
0.1.664 153 9/11/2024 0.1.664 is deprecated.
0.1.653 271 9/11/2024 0.1.653 is deprecated.
0.1.639 343 9/10/2024 0.1.639 is deprecated.
0.1.634 189 9/10/2024 0.1.634 is deprecated.
0.1.623 327 9/7/2024 0.1.623 is deprecated.
0.1.600 588 9/6/2024 0.1.600 is deprecated.
0.1.582 348 9/5/2024 0.1.582 is deprecated.
0.1.578 146 9/5/2024 0.1.578 is deprecated.
0.1.575 136 9/4/2024 0.1.575 is deprecated.
0.1.518 374 9/2/2024 0.1.518 is deprecated.
0.1.512 1,152 8/30/2024 0.1.512 is deprecated.
0.1.508 142 8/29/2024 0.1.508 is deprecated.
0.1.506 217 8/28/2024 0.1.506 is deprecated.
0.1.505 156 8/28/2024 0.1.505 is deprecated.
0.1.504 143 8/28/2024 0.1.504 is deprecated.
0.1.503 187 8/27/2024 0.1.503 is deprecated.
0.1.502 147 8/27/2024 0.1.502 is deprecated.
0.1.497 144 8/27/2024 0.1.497 is deprecated.
0.1.495 149 8/27/2024 0.1.495 is deprecated.
0.1.486 149 8/9/2024 0.1.486 is deprecated.
0.1.481 299 8/8/2024 0.1.481 is deprecated.
0.1.479 157 8/8/2024 0.1.479 is deprecated.
0.1.474 150 8/7/2024 0.1.474 is deprecated.
0.1.471 182 8/7/2024 0.1.471 is deprecated.
0.1.470 131 8/7/2024 0.1.470 is deprecated.
0.1.467 143 8/7/2024 0.1.467 is deprecated.
0.1.455 135 7/31/2024 0.1.455 is deprecated.
0.1.454 109 7/30/2024 0.1.454 is deprecated.