TUnit 0.1.374-alpha01
Prefix ReservedSee the version list below for details.
dotnet add package TUnit --version 0.1.374-alpha01
NuGet\Install-Package TUnit -Version 0.1.374-alpha01
<PackageReference Include="TUnit" Version="0.1.374-alpha01" />
<PackageVersion Include="TUnit" Version="0.1.374-alpha01" />
<PackageReference Include="TUnit" />
paket add TUnit --version 0.1.374-alpha01
#r "nuget: TUnit, 0.1.374-alpha01"
#:package TUnit@0.1.374-alpha01
#addin nuget:?package=TUnit&version=0.1.374-alpha01&prerelease
#tool nuget:?package=TUnit&version=0.1.374-alpha01&prerelease
TUnit
T(est)Unit!
Documentation
See here: https://thomhurst.github.io/TUnit/
Features
- Source generated tests
- Full async support
- Easy to read assertions
- Flexible test data mechanisms
- Flexible setup and cleanup mechanisms
- Out of the box concurrency
- Designed to avoid common pitfalls (leaky test states, shared instances, etc.)
- Global test hooks
- Test context interrogation providing test details and test state
Installation
dotnet add package TUnit --prerelease
Example test
[Test]
public async Task Test1()
{
var value = "Hello world!";
await Assert.That(value)
.Is.Not.Null
.And.Does.StartWith("H")
.And.Has.Count().EqualTo(12)
.And.Is.EqualTo("hello world!", StringComparison.InvariantCultureIgnoreCase);
}
Motivations
There are only three main testing frameworks in the .NET world - xUnit, NUnit and MSTest. More frameworks means more options, and more options motivates more features or improvements.
These testing frameworks are amazing, but I've had some issues with them. You might not have had any of these, but these are my experiences:
xUnit
There is no way to tap into information about a test in a generic way. For example, I've had some Playwright tests run before, and I want them to save a screenshot or video ONLY when the test fails. If the test passes, I don't have anything to investigate, and it'll use up unnecessary storage, and it'll probably slow my test suite down if I had hundreds or thousands of tests all trying to save screenshots.
However, if I'm in a Dispose method which is called when the test ends, then there's no way for me to know if my test succeeded or failed. I'd have to do some really clunky workaround involving try catch and setting a boolean or exception to a class field and checking that. And to do that for every test was just not ideal.
Assertions
I have stumbled across assertions so many times where the arguments are the wrong way round. This can result in really confusing error messages.
var one = 2;
Assert.Equal(1, one)
Assert.Equal(one, 1)
NUnit
Assertions
I absolutely love the newer assertion syntax in NUnit. The Assert.That(something, Is.Something). I think it's really clear to read, it's clear what is being asserted, and it's clear what you're trying to achieve.
However, there is a lack of type checking on assertions. (Yes, there are analyzer packages to help with this, but this still isn't strict type checking.)
Assert.That("1", Throws.Exception);
This assertion makes no sense, because we're passing in a string. This can never throw an exception because it isn't a delegate that can be executed. But it's still perfectly valid code that will compile.
As does this:
Assert.That(1, Does.Contain("Foo!"));
An integer can not contain a string. Of course these will fail at runtime, but we could move these errors up to compile time for faster feedback. This is very useful for long pipelines or build times.
Some methods also just read a little bit weird:
Assert.That(() => Something(), Throws.Exception.Message.Contain(someMessage));
"Throws Exception Message Contain someMessage" - It's not terrible, but it could read a little better.
With TUnit assertions, I wanted to make these impossible to compile. So type constraints are built into the assertions themselves. There should be no way for a non-delegate to be able to do a Throws assertion, or for an int assertion to check for string conditions.
So in TUnit, this will compile:
await Assert.That(() => GetSomeValue()).Throws.Nothing;
This won't:
await Assert.That(GetSomeValue()).Throws.Nothing;
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net7.0
- TUnit.Analyzers (>= 0.1.374-alpha01)
- TUnit.Assertions (>= 0.1.374-alpha01)
- TUnit.Engine (>= 0.1.374-alpha01)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on TUnit:
| Package | Downloads |
|---|---|
|
TUnit.Playwright
A .NET Testing Framework |
|
|
Saucery.TUnit
Sorcery for SauceLabs - Unlocking SauceLabs capability |
|
|
TUnit.AspNetCore
A .NET Testing Framework |
|
|
Rewrite.Test
Test harness for the automated code refactoring framework OpenRewrite. |
|
|
rbkApiModules.Testing.Core
Package Description |
GitHub repositories (67)
Showing the top 20 popular GitHub repositories that depend on TUnit:
| Repository | Stars |
|---|---|
|
MaterialDesignInXAML/MaterialDesignInXamlToolkit
Google's Material Design in XAML & WPF, for C# & VB.Net.
|
|
|
reactiveui/ReactiveUI
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
|
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
|
HMBSbige/NatTypeTester
测试当前网络的 NAT 类型(STUN)
|
|
|
Cysharp/MagicOnion
Unified Realtime/API framework for .NET platform and Unity.
|
|
|
fluentassertions/fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, as well as .NET Core 2.1, .NET Core 3.0, .NET 6, .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
|
|
|
VerifyTests/Verify
Verify is a snapshot testing tool that simplifies the assertion of complex data models and documents.
|
|
|
shouldly/shouldly
Should testing for .NET—the way assertions should be!
|
|
|
reactiveui/Akavache
An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important data as well as cached local data that expires.
|
|
|
OPCFoundation/UA-.NETStandard
OPC Unified Architecture .NET Standard
|
|
|
belav/csharpier
CSharpier is an opinionated code formatter for c#.
|
|
|
Cysharp/ConsoleAppFramework
Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
|
|
|
Nexus-Mods/NexusMods.App
Home of the development of the Nexus Mods App
|
|
|
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
|
|
|
wiremock/WireMock.Net
WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on WireMock Java, but extended and different functionality. Full documentation can be found at https://wiremock.org/dotnet/.
|
|
|
dotnet/skills
Repository for skills to assist AI coding agents with .NET and C#
|
|
|
lookup-foundation/RevitLookup
Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
|
|
|
TNG/ArchUnitNET
A C# architecture test library to specify and assert architecture rules in C# for automated testing.
|
|
|
ncalc/ncalc
NCalc is a fast and lightweight expression evaluator library for .NET, designed for flexibility and high performance. It supports a wide range of mathematical and logical operations.
|
|
|
AwesomeAssertions/AwesomeAssertions
A fork of FluentAssertions controlled by the community.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.40.10 | 1,791 | 4/27/2026 |
| 1.40.5 | 4,832 | 4/27/2026 |
| 1.40.0 | 2,558 | 4/26/2026 |
| 1.39.0 | 12,620 | 4/24/2026 |
| 1.37.36 | 21,798 | 4/22/2026 |
| 1.37.35 | 2,302 | 4/22/2026 |
| 1.37.24 | 17,030 | 4/21/2026 |
| 1.37.10 | 5,967 | 4/20/2026 |
| 1.37.0 | 8,783 | 4/18/2026 |
| 1.36.0 | 2,478 | 4/17/2026 |
| 1.35.2 | 7,654 | 4/16/2026 |
| 1.35.0 | 1,330 | 4/16/2026 |
| 1.34.5 | 11,422 | 4/15/2026 |
| 1.34.0 | 1,570 | 4/15/2026 |
| 1.33.0 | 21,411 | 4/12/2026 |
| 1.32.0 | 5,109 | 4/11/2026 |
| 1.31.0 | 2,046 | 4/11/2026 |
| 1.30.8 | 8,095 | 4/9/2026 |
| 1.30.0 | 4,708 | 4/9/2026 |
| 0.1.374-alpha01 | 180 | 6/25/2024 |