TUnit.Assertions.Analyzers 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.Analyzers.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.370-alpha01
NuGet\Install-Package TUnit.Assertions.Analyzers -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.Analyzers" 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.Analyzers --version 0.1.370-alpha01
#r "nuget: TUnit.Assertions.Analyzers, 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.Analyzers as a Cake Addin
#addin nuget:?package=TUnit.Assertions.Analyzers&version=0.1.370-alpha01&prerelease

// Install TUnit.Assertions.Analyzers as a Cake Tool
#tool nuget:?package=TUnit.Assertions.Analyzers&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 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 (1)

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

Package Downloads
TUnit.Assertions 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 22 6/21/2024
0.1.368-alpha01 19 6/21/2024
0.1.367-alpha01 27 6/21/2024
0.1.366-alpha01 23 6/21/2024
0.1.365-alpha01 35 6/20/2024
0.1.364-alpha01 34 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 33 6/18/2024
0.1.359-alpha01 32 6/17/2024
0.1.358-alpha01 29 6/17/2024
0.1.357-alpha01 41 6/16/2024
0.1.356-alpha01 32 6/16/2024
0.1.355-alpha01 33 6/16/2024
0.1.354-alpha01 32 6/16/2024
0.1.353-alpha01 41 6/16/2024
0.1.352-alpha01 37 6/16/2024
0.1.351-alpha01 39 6/14/2024
0.1.350-alpha01 104 6/14/2024
0.1.349-alpha01 37 6/13/2024
0.1.347-alpha01 34 6/12/2024
0.1.346-alpha01 33 6/12/2024
0.1.343-alpha01 32 6/12/2024
0.1.342-alpha01 30 6/12/2024
0.1.341-alpha01 33 6/11/2024
0.1.340-alpha01 31 6/11/2024
0.1.338-alpha01 31 6/11/2024
0.1.336-alpha01 33 6/11/2024
0.1.335-alpha01 30 6/11/2024
0.1.334-alpha01 34 6/11/2024
0.1.333-alpha01 35 6/11/2024
0.1.332-alpha01 30 6/11/2024
0.1.331-alpha01 33 6/11/2024
0.1.330-alpha01 27 6/11/2024
0.1.329-alpha01 30 6/11/2024
0.1.328-alpha01 31 6/11/2024
0.1.327-alpha01 38 6/10/2024
0.1.326-alpha01 35 6/7/2024
0.1.325-alpha01 35 6/7/2024
0.1.324-alpha01 42 6/6/2024
0.1.323-alpha01 43 6/6/2024
0.1.322-alpha01 37 6/3/2024
0.1.321-alpha01 28 6/3/2024
0.1.320-alpha01 38 6/2/2024
0.1.319-alpha01 43 6/2/2024
0.1.318-alpha01 36 6/2/2024
0.1.317-alpha01 36 6/2/2024
0.1.316-alpha01 41 6/2/2024
0.1.315-alpha01 38 5/31/2024
0.1.314-alpha01 43 5/30/2024
0.1.313-alpha01 34 5/30/2024
0.1.312-alpha01 43 5/29/2024
0.1.311-alpha01 43 5/29/2024
0.1.310-alpha01 36 5/29/2024
0.1.309-alpha01 36 5/29/2024
0.1.308-alpha01 38 5/29/2024
0.1.307-alpha01 35 5/29/2024
0.1.306-alpha01 42 5/29/2024
0.1.305-alpha01 39 5/29/2024
0.1.303-alpha01 39 5/29/2024
0.1.302-alpha01 32 5/29/2024
0.1.301-alpha01 37 5/29/2024
0.1.300-alpha01 35 5/28/2024
0.1.299-alpha01 33 5/28/2024
0.1.298-alpha01 47 5/24/2024
0.1.297-alpha01 47 5/24/2024
0.1.296-alpha01 49 5/23/2024
0.1.295-alpha01 44 5/23/2024
0.1.294-alpha01 48 5/23/2024
0.1.293-alpha01 41 5/21/2024
0.1.292-alpha01 51 5/17/2024
0.1.291-alpha01 45 5/17/2024
0.1.290-alpha01 49 5/16/2024
0.1.289-alpha01 50 5/16/2024
0.1.288-alpha01 366 5/16/2024
0.1.287-alpha01 68 5/15/2024
0.1.286-alpha01 45 5/15/2024
0.1.285-alpha01 39 5/15/2024
0.1.284-alpha01 48 5/15/2024
0.1.283-alpha01 41 5/15/2024
0.1.282-alpha01 74 5/15/2024
0.1.281-alpha01 41 5/15/2024
0.1.280-alpha01 42 5/15/2024
0.1.279-alpha01 42 5/15/2024
0.1.278-alpha01 39 5/15/2024
0.1.277-alpha01 47 5/15/2024
0.1.276-alpha01 33 5/15/2024
0.1.275-alpha01 32 5/15/2024
0.1.274-alpha01 30 5/15/2024
0.1.273-alpha01 29 5/15/2024
0.1.272-alpha01 26 5/15/2024
0.1.271-alpha01 51 5/14/2024
0.1.270-alpha01 40 5/14/2024
0.1.269-alpha01 43 5/14/2024
0.1.267-alpha01 40 5/14/2024
0.1.266-alpha01 35 5/14/2024
0.1.265-alpha01 40 5/14/2024
0.1.264-alpha01 42 5/14/2024
0.1.263-alpha01 42 5/14/2024
0.1.262-alpha01 44 5/14/2024
0.1.261-alpha01 41 5/14/2024
0.1.260-alpha01 38 5/14/2024
0.1.259-alpha01 45 5/14/2024
0.1.258-alpha01 66 5/14/2024
0.1.257-alpha01 47 5/14/2024
0.1.256-alpha01 40 5/14/2024
0.1.255-alpha01 41 5/14/2024
0.1.253-pullrequest0116-0276 38 5/14/2024
0.1.253-pullrequest0116-0274 34 5/14/2024
0.1.253-pullrequest0116-0273 33 5/14/2024
0.1.253-alpha01 40 5/14/2024
0.1.252-alpha01 47 5/13/2024
0.1.251-alpha01 41 5/13/2024
0.1.250-alpha01 41 5/13/2024
0.1.249-alpha01 15 5/3/2024
0.1.248-alpha01 77 4/24/2024
0.1.247-alpha01 53 4/16/2024
0.1.246-alpha01 53 4/16/2024
0.1.245-alpha01 42 4/16/2024
0.1.244-alpha01 39 4/16/2024
0.1.243-alpha01 39 4/16/2024
0.1.242-alpha01 39 4/16/2024
0.1.241-alpha01 49 4/16/2024
0.1.240-alpha01 44 4/16/2024
0.1.239-alpha01 45 4/16/2024
0.1.238-alpha01 44 4/16/2024
0.1.237-alpha01 43 4/16/2024
0.1.236-alpha01 41 4/16/2024
0.1.235-alpha01 44 4/16/2024
0.1.234-alpha01 46 4/16/2024
0.1.233-alpha01 50 4/16/2024
0.1.232-pullrequest0073-0043 77 3/25/2024
0.1.232-alpha01 353 3/26/2024
0.1.231-pullrequest0073-0042 55 2/27/2024
0.1.231-pullrequest0073-0041 72 2/27/2024
0.1.231-pullrequest0073-0040 43 2/27/2024
0.1.231-pullrequest0073-0039 47 2/27/2024
0.1.231-pullrequest0073-0038 46 2/27/2024
0.1.231-pullrequest0073-0037 51 2/27/2024
0.1.231-PullRequest0073.3333 65 2/27/2024
0.1.231-alpha01 53 3/8/2024
0.1.230-alpha01 314 2/25/2024
0.1.229-alpha01 63 2/25/2024
0.1.228-alpha01 45 2/25/2024
0.1.227-alpha01 61 2/25/2024
0.1.225-alpha01 45 2/24/2024
0.1.224-alpha01 80 2/24/2024
0.1.223-alpha01 39 2/24/2024
0.1.222-alpha01 60 2/24/2024
0.1.221-alpha01 45 2/24/2024
0.1.219-alpha01 43 2/24/2024
0.1.218-alpha01 42 2/24/2024
0.1.217-alpha01 51 2/24/2024
0.1.216-alpha01 44 2/24/2024
0.1.215-alpha01 47 2/24/2024
0.1.214-alpha01 67 2/24/2024
0.1.213-alpha01 49 2/24/2024
0.1.212-alpha01 48 2/23/2024
0.1.211-alpha01 53 2/22/2024
0.1.210-alpha01 46 2/22/2024
0.1.209-alpha01 42 2/22/2024
0.1.208-alpha01 47 2/21/2024
0.1.207-alpha01 47 2/21/2024
0.1.206-alpha01 45 2/21/2024
0.1.205-alpha01 51 2/21/2024
0.1.204-alpha01 43 2/19/2024
0.1.203-alpha01 42 2/19/2024
0.1.202-alpha01 44 2/19/2024
0.1.201-alpha01 47 2/19/2024
0.1.200-alpha01 44 2/19/2024
0.1.199-alpha01 45 2/19/2024
0.1.198-alpha01 47 2/19/2024
0.1.197-alpha01 45 2/18/2024
0.1.196-alpha01 42 2/18/2024
0.1.194-alpha01 43 2/18/2024
0.1.193-alpha01 45 2/18/2024
0.1.191-alpha01 44 2/18/2024
0.1.190-alpha01 44 2/18/2024
0.1.189-alpha01 47 2/18/2024
0.1.188-alpha01 43 2/18/2024
0.1.187-alpha01 44 2/18/2024
0.1.186-alpha01 44 2/18/2024
0.1.185-alpha01 44 2/18/2024
0.1.184-alpha01 47 2/18/2024
0.1.183-alpha01 46 2/18/2024
0.1.182-alpha01 45 2/18/2024
0.1.181-alpha01 44 2/18/2024
0.1.180-alpha01 46 2/18/2024
0.1.179-alpha01 43 2/18/2024
0.1.178-alpha01 46 2/18/2024
0.1.177-alpha01 50 2/16/2024
0.1.176-alpha01 45 2/16/2024
0.1.175-alpha01 46 2/16/2024
0.1.174-alpha01 43 2/16/2024
0.1.173-alpha01 42 2/16/2024
0.1.172-alpha01 45 2/16/2024
0.1.171-alpha01 44 2/16/2024
0.1.170-alpha01 48 2/16/2024
0.1.169-alpha01 67 2/16/2024
0.1.168-alpha01 49 2/16/2024
0.1.167-alpha01 44 2/16/2024
0.1.166-alpha01 46 2/16/2024
0.1.164-alpha01 45 2/16/2024
0.1.163-alpha01 48 2/16/2024
0.1.162-alpha01 47 2/16/2024
0.1.158-alpha01 49 2/15/2024
0.1.157-alpha01 44 2/15/2024
0.1.155-alpha01 50 2/15/2024
0.1.154-alpha01 47 2/15/2024
0.1.153-alpha01 44 2/15/2024
0.1.152-alpha01 49 2/15/2024
0.1.151-alpha01 45 2/15/2024
0.1.150-alpha01 48 2/15/2024
0.1.149-alpha01 52 2/15/2024
0.1.148-alpha01 55 2/15/2024
0.1.147-alpha01 49 2/15/2024
0.1.146-alpha01 46 2/15/2024
0.1.145-alpha01 51 2/15/2024
0.1.144-alpha01 47 2/15/2024
0.1.143-alpha01 49 2/14/2024
0.1.142-alpha01 46 2/14/2024
0.1.141-alpha01 46 2/14/2024
0.1.140-alpha01 45 2/14/2024
0.1.139-alpha01 43 2/14/2024
0.1.138-alpha01 47 2/14/2024
0.1.137-alpha01 53 2/13/2024
0.1.136-alpha01 59 2/13/2024
0.1.135-alpha01 51 2/13/2024