TUnit.Playwright 0.2.103

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package TUnit.Playwright --version 0.2.103                
NuGet\Install-Package TUnit.Playwright -Version 0.2.103                
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.Playwright" Version="0.2.103" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TUnit.Playwright --version 0.2.103                
#r "nuget: TUnit.Playwright, 0.2.103"                
#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.Playwright as a Cake Addin
#addin nuget:?package=TUnit.Playwright&version=0.2.103

// Install TUnit.Playwright as a Cake Tool
#tool nuget:?package=TUnit.Playwright&version=0.2.103                

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.7 (23H124) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
Build_TUnit 956.1 ms 18.67 ms 21.50 ms
Build_NUnit 807.9 ms 14.59 ms 12.19 ms
Build_xUnit 844.5 ms 16.87 ms 30.43 ms
Build_MSTest 891.0 ms 17.75 ms 31.55 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.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
Build_TUnit 1.893 s 0.0307 s 0.0287 s
Build_NUnit 1.543 s 0.0246 s 0.0230 s
Build_xUnit 1.543 s 0.0298 s 0.0264 s
Build_MSTest 1.624 s 0.0307 s 0.0302 s
windows-latest

BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2762) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
Build_TUnit 1.964 s 0.0392 s 0.0611 s
Build_NUnit 1.695 s 0.0330 s 0.0462 s
Build_xUnit 1.602 s 0.0217 s 0.0203 s
Build_MSTest 1.645 s 0.0319 s 0.0282 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.7 (23H124) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 118.6 ms 0.47 ms 0.39 ms
TUnit 454.9 ms 7.07 ms 5.52 ms
NUnit 692.5 ms 6.07 ms 5.68 ms
xUnit 681.8 ms 3.12 ms 2.77 ms
MSTest 617.1 ms 6.80 ms 6.36 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.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev Median
TUnit_AOT 64.59 ms 1.267 ms 2.046 ms 63.48 ms
TUnit 826.30 ms 16.092 ms 23.079 ms 823.74 ms
NUnit 1,307.75 ms 18.092 ms 16.924 ms 1,303.09 ms
xUnit 1,287.14 ms 19.870 ms 18.587 ms 1,284.41 ms
MSTest 1,149.21 ms 17.036 ms 15.102 ms 1,148.50 ms
windows-latest

BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2762) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 120.3 ms 2.37 ms 5.05 ms
TUnit 887.4 ms 17.64 ms 29.47 ms
NUnit 1,350.9 ms 19.48 ms 18.23 ms
xUnit 1,318.8 ms 20.37 ms 19.06 ms
MSTest 1,186.9 ms 8.29 ms 7.35 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.7 (23H124) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 301.9 ms 15.98 ms 47.12 ms
TUnit 610.8 ms 20.86 ms 61.50 ms
NUnit 14,298.7 ms 284.71 ms 451.58 ms
xUnit 14,432.4 ms 288.42 ms 608.37 ms
MSTest 14,398.1 ms 275.69 ms 531.17 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.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 139.0 ms 2.75 ms 4.12 ms
TUnit 924.3 ms 18.19 ms 22.33 ms
NUnit 6,490.7 ms 14.60 ms 13.65 ms
xUnit 6,491.2 ms 20.82 ms 19.47 ms
MSTest 6,496.1 ms 31.08 ms 29.07 ms
windows-latest

BenchmarkDotNet v0.14.0, Windows 10 (10.0.20348.2762) (Hyper-V)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 9.0.100-rc.2.24474.11
  [Host]   : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.47305), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 175.8 ms 3.51 ms 9.00 ms
TUnit 971.5 ms 19.31 ms 21.46 ms
NUnit 7,585.5 ms 16.87 ms 15.78 ms
xUnit 7,551.5 ms 18.33 ms 16.25 ms
MSTest 7,524.3 ms 19.40 ms 18.15 ms
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible. 
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.4.45 0 12/1/2024
0.4.43 0 12/1/2024
0.4.31 37 11/30/2024
0.4.26 40 11/30/2024
0.4.14 39 11/29/2024
0.4.10 42 11/28/2024
0.4.1 117 11/24/2024
0.4.0 63 11/24/2024
0.3.43 81 11/22/2024
0.3.34 126 11/19/2024
0.3.31 131 11/18/2024
0.3.30 89 11/18/2024
0.3.29 72 11/18/2024
0.3.25 74 11/17/2024
0.3.20 72 11/17/2024
0.3.14 76 11/17/2024
0.3.12 76 11/16/2024
0.3.3 70 11/16/2024
0.3.0 76 11/16/2024
0.2.212 150 11/11/2024
0.2.210 84 11/11/2024
0.2.208 92 11/11/2024
0.2.206 82 11/11/2024
0.2.202 77 11/9/2024
0.2.195 72 11/6/2024
0.2.193 79 11/5/2024
0.2.191 79 11/5/2024
0.2.187 1,297 11/4/2024
0.2.185 76 11/4/2024
0.2.181 82 11/2/2024
0.2.180 73 11/2/2024
0.2.176 367 11/1/2024
0.2.175 103 11/1/2024
0.2.169 331 10/31/2024
0.2.168 123 10/31/2024
0.2.167 197 10/31/2024
0.2.164 259 10/31/2024
0.2.161 157 10/31/2024
0.2.145 325 10/30/2024
0.2.141 76 10/30/2024
0.2.131 126 10/29/2024
0.2.128 73 10/29/2024
0.2.126 74 10/29/2024
0.2.120 84 10/29/2024
0.2.119 71 10/29/2024
0.2.112 162 10/29/2024
0.2.107 124 10/29/2024
0.2.106 81 10/29/2024
0.2.105 82 10/29/2024
0.2.103 90 10/29/2024
0.2.100 100 10/29/2024
0.2.86 82 10/29/2024
0.2.85 74 10/28/2024
0.2.82 75 10/28/2024
0.2.80 85 10/28/2024