TUnit.Playwright 0.6.33

Prefix Reserved
dotnet add package TUnit.Playwright --version 0.6.33                
NuGet\Install-Package TUnit.Playwright -Version 0.6.33                
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.6.33" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TUnit.Playwright --version 0.6.33                
#r "nuget: TUnit.Playwright, 0.6.33"                
#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.6.33

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

<p align="center"> <img src="assets/banner.png" width="800"/> <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> </p>

A modern, flexible and fast testing framework for C#. 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/

Modern and Fast

TUnit leverages source generators to locate and register your tests as opposed to reflection. You'll have a slight bump in build time, but a speedier runtime.

TUnit also builds upon the newer Microsoft.Testing.Platform, whereas most other frameworks you'll have used will use VSTest. The new platform was reconstructed from the ground up to address pain points, be more extensible, and be faster.

Hooks, Events and Lifecycles

One of the most powerful parts of TUnit is the information you have available to you because of the source generation and the events you can subscribe to. Because tests are constructed at the point of discovery, and not at runtime, you know all your arguments, properties, etc. upfront.

You can then register to be notified about various events such as test registered (scheduled to run in this test session at some point in the future), test started, test finished, etc.

Say we injected an external object into our tests: By knowing how many tests are registered, we could count them up, and then on a test end event, we could decrease the count. When hitting 0, we know our object isn't going to be used by any other tests, so we can dispose of it. We know when we can handle the lifecycle, and this prevents it from living till the end of the test session where it could be hanging on to precious resources.

Built in Analyzers

TUnit tries to help you write your tests correctly with analyzers. If something isn't quite right, an analyzer should tell you what's wrong.

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. The "Use testing platform server mode" option must be selected in Tools > Manage Preview Features.

<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!

Packages

TUnit.Core

To be used when you want to define re-useable components, such as a test library, but it wouldn't be run as its own test suite.

TUnit.Engine

For test suites. This contains the test execution logic and test adapter. Only install this on actual test projects you intend to run, not class libraries.

TUnit.Assertions

This is independent from the framework and can be used wherever - Even in other test frameworks. It is just an assertion library used to assert data is as you expect. It uses an asychronous syntax which may be different to other assertion libraries you may have used.

TUnit

This is a helper package to combine the above 3 packages. If you just want a standard test app where you can write, run and assert tests, just install this!

TUnit.Playwright

This provides you base classes, similarly to Microsoft.Playwright.NUnit or Microsoft.Playwright.MSTest, to automatically create and dispose of Playwright objects in tests, to make it easier for you to write tests without worrying about lifecycles or disposing. The base classes are named the same as the other libraries: PageTest, ContextTest, BrowserTest, and PlaywrightTest.

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")]
    [MethodDataSource(nameof(GetAuthDetails))]
    public async Task Register(string username, string password) { ... }

    [Repeat(5)]
    [Test, DependsOn(nameof(Register))]
    [MethodDataSource(nameof(GetAuthDetails))]
    public async Task Login(string username, string password) { ... }

    [Test, DependsOn(nameof(Login), [typeof(string), typeof(string)])]
    [MethodDataSource(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.2 (23H311) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev Median
Build_TUnit 923.7 ms 16.17 ms 13.50 ms 926.4 ms
Build_NUnit 805.7 ms 13.04 ms 11.56 ms 803.9 ms
Build_xUnit 815.7 ms 14.47 ms 27.54 ms 804.3 ms
Build_MSTest 884.0 ms 18.13 ms 52.89 ms 879.8 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.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
Build_TUnit 1.801 s 0.0343 s 0.0337 s
Build_NUnit 1.476 s 0.0225 s 0.0210 s
Build_xUnit 1.482 s 0.0231 s 0.0205 s
Build_MSTest 1.546 s 0.0192 s 0.0170 s
windows-latest

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

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
Build_TUnit 1.782 s 0.0327 s 0.0349 s
Build_NUnit 1.466 s 0.0255 s 0.0239 s
Build_xUnit 1.475 s 0.0258 s 0.0242 s
Build_MSTest 1.511 s 0.0161 s 0.0150 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.2 (23H311) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev Median
TUnit_AOT 96.80 ms 5.777 ms 16.853 ms 87.78 ms
TUnit 498.64 ms 9.696 ms 9.523 ms 500.04 ms
NUnit 753.81 ms 12.174 ms 10.166 ms 753.00 ms
xUnit 771.06 ms 6.771 ms 6.002 ms 771.67 ms
MSTest 689.18 ms 13.689 ms 19.632 ms 690.05 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.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 36.29 ms 1.155 ms 3.351 ms
TUnit 835.26 ms 16.561 ms 26.743 ms
NUnit 1,304.85 ms 20.355 ms 19.040 ms
xUnit 1,343.64 ms 12.228 ms 11.438 ms
MSTest 1,145.49 ms 11.723 ms 10.392 ms
windows-latest

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

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 77.63 ms 1.429 ms 1.267 ms
TUnit 836.06 ms 16.451 ms 21.962 ms
NUnit 1,296.24 ms 7.067 ms 6.265 ms
xUnit 1,333.18 ms 25.603 ms 23.949 ms
MSTest 1,140.66 ms 10.591 ms 9.907 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.2 (23H311) [Darwin 23.6.0]
Apple M1 (Virtual), 1 CPU, 3 logical and 3 physical cores
.NET SDK 9.0.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), Arm64 RyuJIT AdvSIMD

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 242.5 ms 11.35 ms 33.28 ms
TUnit 614.8 ms 19.20 ms 56.60 ms
NUnit 14,273.4 ms 283.77 ms 553.47 ms
xUnit 14,196.6 ms 283.16 ms 531.84 ms
MSTest 14,350.2 ms 283.74 ms 553.41 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.101
  [Host]   : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
  .NET 9.0 : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev
TUnit_AOT 77.74 ms 1.530 ms 1.700 ms
TUnit 907.20 ms 17.724 ms 21.099 ms
NUnit 6,498.42 ms 30.349 ms 28.388 ms
xUnit 6,535.76 ms 12.576 ms 10.502 ms
MSTest 6,452.03 ms 29.910 ms 27.978 ms
windows-latest

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

Job=.NET 9.0  Runtime=.NET 9.0  

Method Mean Error StdDev Median
TUnit_AOT 128.0 ms 2.91 ms 8.59 ms 125.4 ms
TUnit 901.2 ms 17.90 ms 26.24 ms 905.1 ms
NUnit 7,477.6 ms 19.21 ms 17.97 ms 7,479.6 ms
xUnit 7,553.1 ms 15.92 ms 14.89 ms 7,554.6 ms
MSTest 7,433.2 ms 18.67 ms 17.46 ms 7,432.9 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 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. 
.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.6.33 64 1/5/2025
0.6.15 83 12/30/2024
0.6.14 71 12/30/2024
0.6.11 84 12/29/2024
0.6.0 84 12/26/2024
0.5.32 75 12/24/2024
0.5.28 74 12/23/2024
0.5.22 89 12/20/2024
0.5.18 78 12/20/2024
0.5.15 75 12/19/2024
0.5.14 78 12/19/2024
0.5.6 316 12/16/2024
0.5.4 68 12/16/2024
0.5.1 75 12/16/2024
0.5.0 79 12/16/2024
0.4.105 87 12/12/2024
0.4.99 88 12/11/2024
0.4.95 190 12/10/2024
0.4.92 95 12/9/2024
0.4.86 93 12/7/2024
0.4.83 85 12/7/2024
0.4.74 616 12/4/2024
0.4.73 90 12/4/2024
0.4.71 88 12/4/2024
0.4.63 465 12/3/2024
0.4.60 214 12/3/2024
0.4.59 101 12/3/2024
0.4.56 93 12/2/2024
0.4.54 74 12/2/2024
0.4.51 86 12/2/2024
0.4.49 84 12/2/2024
0.4.45 84 12/1/2024
0.4.43 84 12/1/2024
0.4.31 85 11/30/2024
0.4.26 81 11/30/2024
0.4.14 80 11/29/2024
0.4.10 83 11/28/2024
0.4.1 141 11/24/2024
0.4.0 78 11/24/2024
0.3.43 90 11/22/2024
0.3.34 165 11/19/2024
0.3.31 140 11/18/2024
0.3.30 99 11/18/2024
0.3.29 79 11/18/2024
0.3.25 85 11/17/2024
0.3.20 80 11/17/2024
0.3.14 84 11/17/2024
0.3.12 88 11/16/2024
0.3.3 80 11/16/2024
0.3.0 84 11/16/2024
0.2.212 161 11/11/2024
0.2.210 97 11/11/2024
0.2.208 103 11/11/2024
0.2.206 95 11/11/2024
0.2.202 88 11/9/2024
0.2.195 83 11/6/2024
0.2.193 89 11/5/2024
0.2.191 90 11/5/2024
0.2.187 1,308 11/4/2024
0.2.185 87 11/4/2024
0.2.181 94 11/2/2024
0.2.180 84 11/2/2024
0.2.176 376 11/1/2024
0.2.175 112 11/1/2024
0.2.169 342 10/31/2024
0.2.168 134 10/31/2024
0.2.167 207 10/31/2024
0.2.164 273 10/31/2024
0.2.161 166 10/31/2024
0.2.145 334 10/30/2024
0.2.141 87 10/30/2024
0.2.131 138 10/29/2024
0.2.128 85 10/29/2024
0.2.126 84 10/29/2024
0.2.120 96 10/29/2024
0.2.119 83 10/29/2024
0.2.112 174 10/29/2024
0.2.107 135 10/29/2024
0.2.106 92 10/29/2024
0.2.105 93 10/29/2024
0.2.103 99 10/29/2024
0.2.100 112 10/29/2024
0.2.86 92 10/29/2024
0.2.85 81 10/28/2024
0.2.82 85 10/28/2024
0.2.80 96 10/28/2024