TUnit.Assertions 0.1.370-alpha01

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of TUnit.Assertions.
dotnet add package TUnit.Assertions --version 0.1.370-alpha01
NuGet\Install-Package TUnit.Assertions -Version 0.1.370-alpha01
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" Version="0.1.370-alpha01" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TUnit.Assertions --version 0.1.370-alpha01
#r "nuget: TUnit.Assertions, 0.1.370-alpha01"
#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 as a Cake Addin
#addin nuget:?package=TUnit.Assertions&version=0.1.370-alpha01&prerelease

// Install TUnit.Assertions as a Cake Tool
#tool nuget:?package=TUnit.Assertions&version=0.1.370-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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TUnit.Assertions:

Package Downloads
TUnit The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.370-alpha01 22 6/21/2024
0.1.369-alpha01 24 6/21/2024
0.1.368-alpha01 24 6/21/2024
0.1.367-alpha01 25 6/21/2024
0.1.366-alpha01 23 6/21/2024
0.1.365-alpha01 31 6/20/2024
0.1.364-alpha01 31 6/19/2024
0.1.363-alpha01 31 6/19/2024
0.1.362-alpha01 34 6/18/2024
0.1.361-alpha01 31 6/18/2024
0.1.360-alpha01 31 6/18/2024
0.1.359-alpha01 32 6/17/2024
0.1.358-alpha01 28 6/17/2024
0.1.357-alpha01 36 6/16/2024
0.1.356-alpha01 31 6/16/2024
0.1.355-alpha01 35 6/16/2024
0.1.354-alpha01 34 6/16/2024
0.1.353-alpha01 39 6/16/2024
0.1.352-alpha01 36 6/16/2024
0.1.351-alpha01 39 6/14/2024
0.1.350-alpha01 106 6/14/2024
0.1.349-alpha01 37 6/13/2024
0.1.347-alpha01 32 6/12/2024
0.1.346-alpha01 32 6/12/2024
0.1.343-alpha01 33 6/12/2024
0.1.342-alpha01 33 6/12/2024
0.1.341-alpha01 34 6/11/2024
0.1.340-alpha01 34 6/11/2024
0.1.338-alpha01 34 6/11/2024
0.1.336-alpha01 36 6/11/2024
0.1.335-alpha01 34 6/11/2024
0.1.334-alpha01 34 6/11/2024
0.1.333-alpha01 33 6/11/2024
0.1.332-alpha01 33 6/11/2024
0.1.331-alpha01 30 6/11/2024
0.1.330-alpha01 32 6/11/2024
0.1.329-alpha01 33 6/11/2024
0.1.328-alpha01 35 6/11/2024
0.1.327-alpha01 40 6/10/2024
0.1.326-alpha01 31 6/7/2024
0.1.325-alpha01 33 6/7/2024
0.1.324-alpha01 43 6/6/2024
0.1.323-alpha01 44 6/6/2024
0.1.322-alpha01 39 6/3/2024
0.1.321-alpha01 28 6/3/2024
0.1.320-alpha01 58 6/2/2024
0.1.319-alpha01 42 6/2/2024
0.1.318-alpha01 36 6/2/2024
0.1.317-alpha01 41 6/2/2024
0.1.316-alpha01 37 6/2/2024
0.1.315-alpha01 41 5/31/2024
0.1.314-alpha01 49 5/30/2024
0.1.313-alpha01 37 5/30/2024
0.1.312-alpha01 44 5/29/2024
0.1.311-alpha01 47 5/29/2024
0.1.310-alpha01 42 5/29/2024
0.1.309-alpha01 39 5/29/2024
0.1.308-alpha01 40 5/29/2024
0.1.307-alpha01 40 5/29/2024
0.1.306-alpha01 42 5/29/2024
0.1.305-alpha01 42 5/29/2024
0.1.303-alpha01 41 5/29/2024
0.1.302-alpha01 35 5/29/2024
0.1.301-alpha01 37 5/29/2024
0.1.300-alpha01 36 5/28/2024
0.1.299-alpha01 37 5/28/2024
0.1.298-alpha01 45 5/24/2024
0.1.297-alpha01 51 5/24/2024
0.1.296-alpha01 49 5/23/2024
0.1.295-alpha01 44 5/23/2024
0.1.294-alpha01 50 5/23/2024
0.1.293-alpha01 46 5/21/2024
0.1.292-alpha01 52 5/17/2024
0.1.291-alpha01 50 5/17/2024
0.1.290-alpha01 54 5/16/2024
0.1.289-alpha01 48 5/16/2024
0.1.288-alpha01 358 5/16/2024
0.1.287-alpha01 79 5/15/2024
0.1.286-alpha01 52 5/15/2024
0.1.285-alpha01 54 5/15/2024
0.1.284-alpha01 54 5/15/2024
0.1.283-alpha01 45 5/15/2024
0.1.282-alpha01 80 5/15/2024
0.1.281-alpha01 49 5/15/2024
0.1.280-alpha01 53 5/15/2024
0.1.279-alpha01 45 5/15/2024
0.1.278-alpha01 45 5/15/2024
0.1.277-alpha01 44 5/15/2024
0.1.276-alpha01 36 5/15/2024
0.1.275-alpha01 42 5/15/2024
0.1.274-alpha01 35 5/15/2024
0.1.273-alpha01 30 5/15/2024
0.1.272-alpha01 27 5/15/2024
0.1.271-alpha01 47 5/14/2024
0.1.270-alpha01 43 5/14/2024
0.1.269-alpha01 47 5/14/2024
0.1.267-alpha01 50 5/14/2024
0.1.266-alpha01 36 5/14/2024
0.1.265-alpha01 45 5/14/2024
0.1.264-alpha01 41 5/14/2024
0.1.263-alpha01 47 5/14/2024
0.1.262-alpha01 47 5/14/2024
0.1.261-alpha01 49 5/14/2024
0.1.260-alpha01 46 5/14/2024
0.1.259-alpha01 43 5/14/2024
0.1.258-alpha01 68 5/14/2024
0.1.257-alpha01 61 5/14/2024
0.1.256-alpha01 45 5/14/2024
0.1.255-alpha01 41 5/14/2024
0.1.253-pullrequest0116-0276 46 5/14/2024
0.1.253-pullrequest0116-0274 39 5/14/2024
0.1.253-pullrequest0116-0273 38 5/14/2024
0.1.253-alpha01 46 5/14/2024
0.1.252-alpha01 54 5/13/2024
0.1.251-alpha01 44 5/13/2024
0.1.250-alpha01 44 5/13/2024
0.1.249-alpha01 17 5/3/2024
0.1.248-alpha01 80 4/24/2024
0.1.247-alpha01 53 4/16/2024
0.1.246-alpha01 55 4/16/2024
0.1.245-alpha01 50 4/16/2024
0.1.244-alpha01 56 4/16/2024
0.1.243-alpha01 51 4/16/2024
0.1.242-alpha01 48 4/16/2024
0.1.241-alpha01 44 4/16/2024
0.1.240-alpha01 47 4/16/2024
0.1.239-alpha01 45 4/16/2024
0.1.238-alpha01 49 4/16/2024
0.1.237-alpha01 49 4/16/2024
0.1.236-alpha01 42 4/16/2024
0.1.235-alpha01 44 4/16/2024
0.1.234-alpha01 47 4/16/2024
0.1.233-alpha01 48 4/16/2024
0.1.232-pullrequest0073-0043 82 3/25/2024
0.1.232-alpha01 365 3/26/2024
0.1.231-pullrequest0073-0042 55 2/27/2024
0.1.231-pullrequest0073-0041 89 2/27/2024
0.1.231-pullrequest0073-0040 45 2/27/2024
0.1.231-pullrequest0073-0039 55 2/27/2024
0.1.231-pullrequest0073-0038 51 2/27/2024
0.1.231-pullrequest0073-0037 57 2/27/2024
0.1.231-PullRequest0073.3333 68 2/27/2024
0.1.231-alpha01 50 3/8/2024
0.1.230-alpha01 314 2/25/2024
0.1.229-alpha01 60 2/25/2024
0.1.228-alpha01 45 2/25/2024
0.1.227-alpha01 63 2/25/2024
0.1.225-alpha01 47 2/24/2024
0.1.224-alpha01 83 2/24/2024
0.1.223-alpha01 46 2/24/2024
0.1.222-alpha01 63 2/24/2024
0.1.221-alpha01 46 2/24/2024
0.1.219-alpha01 45 2/24/2024
0.1.218-alpha01 48 2/24/2024
0.1.217-alpha01 52 2/24/2024
0.1.216-alpha01 46 2/24/2024
0.1.215-alpha01 44 2/24/2024
0.1.214-alpha01 69 2/24/2024
0.1.213-alpha01 51 2/24/2024
0.1.212-alpha01 55 2/23/2024
0.1.211-alpha01 52 2/22/2024
0.1.210-alpha01 43 2/22/2024
0.1.209-alpha01 48 2/22/2024
0.1.208-alpha01 52 2/21/2024
0.1.207-alpha01 55 2/21/2024
0.1.206-alpha01 52 2/21/2024
0.1.205-alpha01 47 2/21/2024
0.1.204-alpha01 44 2/19/2024
0.1.203-alpha01 44 2/19/2024
0.1.202-alpha01 46 2/19/2024
0.1.201-alpha01 47 2/19/2024
0.1.200-alpha01 46 2/19/2024
0.1.199-alpha01 46 2/19/2024
0.1.198-alpha01 44 2/19/2024
0.1.197-alpha01 48 2/18/2024
0.1.196-alpha01 43 2/18/2024
0.1.194-alpha01 44 2/18/2024
0.1.193-alpha01 43 2/18/2024
0.1.191-alpha01 45 2/18/2024
0.1.190-alpha01 42 2/18/2024
0.1.189-alpha01 46 2/18/2024
0.1.188-alpha01 43 2/18/2024
0.1.187-alpha01 45 2/18/2024
0.1.186-alpha01 45 2/18/2024
0.1.185-alpha01 43 2/18/2024
0.1.184-alpha01 43 2/18/2024
0.1.183-alpha01 45 2/18/2024
0.1.182-alpha01 48 2/18/2024
0.1.181-alpha01 46 2/18/2024
0.1.180-alpha01 42 2/18/2024
0.1.179-alpha01 46 2/18/2024
0.1.178-alpha01 44 2/18/2024
0.1.177-alpha01 47 2/16/2024
0.1.176-alpha01 44 2/16/2024
0.1.175-alpha01 45 2/16/2024
0.1.174-alpha01 48 2/16/2024
0.1.173-alpha01 44 2/16/2024
0.1.172-alpha01 42 2/16/2024
0.1.171-alpha01 46 2/16/2024
0.1.170-alpha01 42 2/16/2024
0.1.169-alpha01 46 2/16/2024
0.1.168-alpha01 52 2/16/2024
0.1.167-alpha01 45 2/16/2024
0.1.166-alpha01 46 2/16/2024
0.1.164-alpha01 44 2/16/2024
0.1.163-alpha01 44 2/16/2024
0.1.162-alpha01 44 2/16/2024
0.1.158-alpha01 49 2/15/2024
0.1.157-alpha01 45 2/15/2024
0.1.155-alpha01 51 2/15/2024
0.1.154-alpha01 48 2/15/2024
0.1.153-alpha01 47 2/15/2024
0.1.152-alpha01 48 2/15/2024
0.1.151-alpha01 45 2/15/2024
0.1.150-alpha01 51 2/15/2024
0.1.149-alpha01 50 2/15/2024
0.1.148-alpha01 49 2/15/2024
0.1.147-alpha01 52 2/15/2024
0.1.146-alpha01 47 2/15/2024
0.1.145-alpha01 46 2/15/2024
0.1.144-alpha01 50 2/15/2024
0.1.143-alpha01 47 2/14/2024
0.1.142-alpha01 45 2/14/2024
0.1.141-alpha01 47 2/14/2024
0.1.140-alpha01 44 2/14/2024
0.1.139-alpha01 42 2/14/2024
0.1.138-alpha01 46 2/14/2024
0.1.137-alpha01 54 2/13/2024
0.1.136-alpha01 51 2/13/2024
0.1.135-alpha01 51 2/13/2024
0.1.134-alpha01 50 2/13/2024
0.1.133-alpha01 47 2/13/2024
0.1.132-alpha01 49 2/13/2024
0.1.131-alpha01 49 2/13/2024
0.1.130-alpha01 48 2/11/2024
0.1.129-alpha01 166 2/11/2024
0.1.128-alpha01 51 2/11/2024
0.1.127-alpha01 50 2/11/2024
0.1.126-alpha01 46 2/11/2024
0.1.125-alpha01 49 2/11/2024
0.1.124-alpha01 54 2/11/2024
0.1.123-alpha01 49 2/11/2024
0.1.122-alpha01 48 2/10/2024
0.1.121-alpha01 48 2/10/2024
0.1.120-alpha01 48 2/10/2024
0.1.119-alpha01 46 2/10/2024
0.1.118-alpha01 47 2/10/2024
0.1.117-alpha01 49 2/9/2024
0.1.116-alpha01 47 2/9/2024
0.1.115-alpha01 47 2/9/2024
0.1.114-alpha01 44 2/9/2024
0.1.113-alpha01 47 2/9/2024
0.1.112-alpha01 48 2/9/2024
0.1.111-alpha01 48 2/9/2024
0.1.110-alpha01 60 2/8/2024
0.1.109-alpha01 60 2/8/2024
0.1.108-alpha01 49 2/8/2024
0.1.107-alpha01 47 2/8/2024
0.1.106-alpha01 49 2/8/2024
0.1.105-alpha01 49 2/8/2024
0.1.104-alpha01 69 2/8/2024
0.1.103-alpha01 47 2/8/2024
0.1.102-alpha01 46 2/8/2024
0.1.101-alpha01 60 2/8/2024
0.1.100-alpha01 45 2/8/2024
0.1.99-alpha01 46 2/8/2024
0.1.98-alpha01 45 2/8/2024
0.1.97-alpha01 48 2/8/2024
0.1.96-alpha01 95 2/7/2024
0.1.95-alpha01 56 2/7/2024
0.1.94-alpha01 79 2/7/2024
0.1.93-alpha01 50 2/7/2024
0.1.92-alpha01 47 2/7/2024
0.1.91-alpha01 52 2/7/2024
0.1.90-alpha01 49 2/7/2024
0.1.89-alpha01 46 2/7/2024
0.1.88-alpha01 48 2/7/2024
0.1.87-alpha01 51 2/7/2024
0.1.86-alpha01 57 2/7/2024
0.1.85-alpha01 55 2/7/2024
0.1.84-alpha01 54 2/7/2024
0.1.83-alpha01 55 2/7/2024
0.1.82-alpha01 49 2/7/2024
0.1.81-alpha01 49 2/7/2024
0.1.80-alpha01 52 2/7/2024
0.1.79-alpha01 46 2/7/2024
0.1.78-alpha01 50 2/7/2024
0.1.77-alpha01 50 2/7/2024
0.1.75-alpha01 54 2/7/2024
0.1.74-alpha01 47 2/7/2024
0.1.72-alpha01 47 2/7/2024
0.1.71-alpha01 51 2/7/2024
0.1.70-alpha01 52 2/7/2024
0.1.69-alpha01 47 2/6/2024
0.1.68-alpha01 66 2/6/2024
0.1.67-alpha01 49 2/6/2024
0.1.66-alpha01 49 2/6/2024
0.1.65-alpha01 54 2/6/2024
0.1.64-alpha01 54 2/6/2024
0.1.63-alpha01 53 2/6/2024
0.1.62-alpha01 47 2/6/2024
0.1.61-alpha01 53 2/6/2024
0.1.60-alpha01 47 2/6/2024
0.1.59-alpha01 52 2/6/2024
0.1.58-alpha01 51 2/6/2024
0.1.57-alpha01 48 2/6/2024
0.1.56-alpha01 48 2/6/2024
0.1.55-alpha01 50 2/6/2024
0.1.54-alpha01 53 2/6/2024
0.1.53-alpha01 51 2/6/2024
0.1.52-alpha01 51 2/6/2024
0.1.51-alpha01 48 2/6/2024
0.1.50-alpha01 52 2/6/2024
0.1.49-alpha01 51 2/5/2024
0.1.48-alpha01 50 2/5/2024
0.1.47-alpha01 56 2/5/2024
0.1.45-alpha01 59 2/5/2024
0.1.44-alpha01 53 2/5/2024
0.1.43-alpha01 54 2/5/2024
0.1.42-alpha01 48 2/5/2024
0.1.41-alpha01 51 2/5/2024
0.1.40-alpha01 51 2/5/2024
0.1.39-alpha01 50 2/5/2024
0.1.38-alpha01 51 2/5/2024
0.1.37-alpha01 49 2/5/2024
0.1.36-alpha01 48 2/5/2024
0.1.35-alpha01 50 2/5/2024
0.1.34-alpha01 60 2/5/2024
0.1.33-alpha01 63 2/5/2024
0.1.32-alpha01 52 2/5/2024
0.1.31-alpha01 53 2/5/2024
0.1.30-alpha01 50 2/5/2024
0.1.29-alpha01 54 2/5/2024
0.1.27-alpha01 48 2/5/2024
0.1.26-alpha01 54 2/5/2024
0.1.25-alpha01 47 2/5/2024
0.1.24-alpha01 49 2/4/2024
0.1.23-alpha01 49 2/4/2024
0.1.22-alpha01 52 2/4/2024
0.1.21-alpha01 57 2/4/2024
0.1.20-alpha01 55 2/4/2024
0.1.19-alpha01 56 2/4/2024
0.1.18-alpha01 51 2/4/2024
0.1.17-alpha01 49 2/4/2024
0.1.14-alpha01 52 2/4/2024
0.1.13-alpha01 54 2/4/2024
0.1.12-alpha01 47 2/4/2024
0.1.11-alpha01 52 2/4/2024
0.1.10-alpha01 47 2/4/2024
0.1.9-alpha01 54 2/4/2024
0.1.0-alpha01 52 2/4/2024