TUnit.Engine.SourceGenerator 0.1.984

Prefix Reserved
Suggested Alternatives

TUnit.Core

Additional Details

TUnit.Core handles SourceGeneration now.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package TUnit.Engine.SourceGenerator --version 0.1.984                
NuGet\Install-Package TUnit.Engine.SourceGenerator -Version 0.1.984                
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.Engine.SourceGenerator" Version="0.1.984" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TUnit.Engine.SourceGenerator --version 0.1.984                
#r "nuget: TUnit.Engine.SourceGenerator, 0.1.984"                
#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.Engine.SourceGenerator as a Cake Addin
#addin nuget:?package=TUnit.Engine.SourceGenerator&version=0.1.984

// Install TUnit.Engine.SourceGenerator as a Cake Tool
#tool nuget:?package=TUnit.Engine.SourceGenerator&version=0.1.984                

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!

GitHub Repo stars GitHub Sponsors nuget NuGet Downloads 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 870.7 ms 16.82 ms 27.17 ms
Build_NUnit 811.7 ms 16.12 ms 22.06 ms
Build_xUnit 798.5 ms 5.65 ms 4.72 ms
Build_MSTest 843.5 ms 14.01 ms 12.42 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.634 s 0.0207 s 0.0183 s
Build_NUnit 1.483 s 0.0233 s 0.0217 s
Build_xUnit 1.493 s 0.0165 s 0.0147 s
Build_MSTest 1.554 s 0.0166 s 0.0155 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.713 s 0.0293 s 0.0274 s
Build_NUnit 1.550 s 0.0165 s 0.0154 s
Build_xUnit 1.547 s 0.0236 s 0.0221 s
Build_MSTest 1.592 s 0.0120 s 0.0107 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 Median
TUnit_AOT 76.51 ms 2.358 ms 6.802 ms 74.17 ms
TUnit 431.76 ms 5.574 ms 4.655 ms 432.10 ms
NUnit 700.28 ms 6.158 ms 5.459 ms 698.76 ms
xUnit 894.38 ms 39.315 ms 115.305 ms 868.56 ms
MSTest 727.47 ms 20.541 ms 59.593 ms 723.53 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.31 ms 1.004 ms 2.914 ms
TUnit 766.14 ms 14.988 ms 14.020 ms
NUnit 1,320.07 ms 9.137 ms 8.100 ms
xUnit 1,303.64 ms 10.966 ms 10.257 ms
MSTest 1,174.30 ms 7.512 ms 7.027 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.97 ms 0.184 ms 0.144 ms
TUnit 800.71 ms 15.697 ms 27.076 ms
NUnit 1,361.81 ms 21.911 ms 20.495 ms
xUnit 1,336.83 ms 23.869 ms 21.160 ms
MSTest 1,213.57 ms 17.851 ms 16.698 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 239.9 ms 14.49 ms 42.73 ms
TUnit 837.7 ms 49.91 ms 147.15 ms
NUnit 14,792.6 ms 292.96 ms 585.07 ms
xUnit 14,381.4 ms 282.18 ms 589.01 ms
MSTest 14,454.1 ms 288.27 ms 519.81 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 Median
TUnit_AOT 100.1 ms 1.97 ms 3.18 ms 101.7 ms
TUnit 849.6 ms 16.86 ms 17.31 ms 852.4 ms
NUnit 6,318.2 ms 19.53 ms 17.31 ms 6,322.0 ms
xUnit 6,418.7 ms 15.18 ms 14.20 ms 6,422.9 ms
MSTest 6,351.4 ms 18.76 ms 17.55 ms 6,350.3 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.2 ms 2.77 ms 3.69 ms
TUnit 889.9 ms 17.51 ms 29.74 ms
NUnit 7,590.2 ms 16.32 ms 14.47 ms
xUnit 7,558.2 ms 22.74 ms 21.27 ms
MSTest 7,518.0 ms 18.52 ms 17.32 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