TUnit.Assertions.Analyzers 0.1.358-alpha01

Prefix Reserved
Suggested Alternatives

TUnit.Assertions

Additional Details

TUnit.Assertions handles analyzing natively now.

This is a prerelease version of TUnit.Assertions.Analyzers.
There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.358-alpha01                
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.358-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.358-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.358-alpha01                
#r "nuget: TUnit.Assertions.Analyzers, 0.1.358-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.358-alpha01&prerelease

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

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.1.984 594 10/7/2024 0.1.984 is deprecated.
0.1.980 82 10/7/2024 0.1.980 is deprecated.
0.1.971 81 10/7/2024 0.1.971 is deprecated.
0.1.966 95 10/7/2024 0.1.966 is deprecated.
0.1.962 86 10/6/2024 0.1.962 is deprecated.
0.1.961 85 10/6/2024 0.1.961 is deprecated.
0.1.958 82 10/6/2024 0.1.958 is deprecated.
0.1.954 91 10/6/2024 0.1.954 is deprecated.
0.1.949 84 10/6/2024 0.1.949 is deprecated.
0.1.942 90 10/5/2024 0.1.942 is deprecated.
0.1.939 85 10/5/2024 0.1.939 is deprecated.
0.1.937 87 10/5/2024 0.1.937 is deprecated.
0.1.934 83 10/5/2024 0.1.934 is deprecated.
0.1.931 89 10/5/2024 0.1.931 is deprecated.
0.1.928 86 10/4/2024 0.1.928 is deprecated.
0.1.923 90 10/4/2024 0.1.923 is deprecated.
0.1.916 85 10/3/2024 0.1.916 is deprecated.
0.1.911 98 10/3/2024 0.1.911 is deprecated.
0.1.897 116 10/2/2024 0.1.897 is deprecated.
0.1.894 88 10/2/2024 0.1.894 is deprecated.
0.1.891 91 10/2/2024 0.1.891 is deprecated.
0.1.885 91 10/1/2024 0.1.885 is deprecated.
0.1.877 94 9/29/2024 0.1.877 is deprecated.
0.1.872 101 9/29/2024 0.1.872 is deprecated.
0.1.869 93 9/29/2024 0.1.869 is deprecated.
0.1.864 92 9/28/2024 0.1.864 is deprecated.
0.1.863 95 9/28/2024 0.1.863 is deprecated.
0.1.857 90 9/28/2024 0.1.857 is deprecated.
0.1.842 95 9/26/2024 0.1.842 is deprecated.
0.1.827 93 9/25/2024 0.1.827 is deprecated.
0.1.818 92 9/24/2024 0.1.818 is deprecated.
0.1.817 88 9/24/2024 0.1.817 is deprecated.
0.1.816 89 9/24/2024 0.1.816 is deprecated.
0.1.812 101 9/23/2024 0.1.812 is deprecated.
0.1.807 90 9/23/2024 0.1.807 is deprecated.
0.1.804 110 9/22/2024 0.1.804 is deprecated.
0.1.801 99 9/22/2024 0.1.801 is deprecated.
0.1.797 90 9/22/2024 0.1.797 is deprecated.
0.1.793 110 9/21/2024 0.1.793 is deprecated.
0.1.791 88 9/21/2024 0.1.791 is deprecated.
0.1.790 87 9/21/2024 0.1.790 is deprecated.
0.1.783 100 9/20/2024 0.1.783 is deprecated.
0.1.773 95 9/20/2024 0.1.773 is deprecated.
0.1.767 95 9/19/2024 0.1.767 is deprecated.
0.1.763 94 9/19/2024 0.1.763 is deprecated.
0.1.762 98 9/19/2024 0.1.762 is deprecated.
0.1.759 98 9/19/2024 0.1.759 is deprecated.
0.1.752 93 9/18/2024 0.1.752 is deprecated.
0.1.741 96 9/17/2024 0.1.741 is deprecated.
0.1.738 118 9/16/2024 0.1.738 is deprecated.
0.1.732 115 9/16/2024 0.1.732 is deprecated.
0.1.720 109 9/15/2024 0.1.720 is deprecated.
0.1.716 115 9/15/2024 0.1.716 is deprecated.
0.1.714 109 9/15/2024 0.1.714 is deprecated.
0.1.711 103 9/15/2024 0.1.711 is deprecated.
0.1.703 323 9/14/2024 0.1.703 is deprecated.
0.1.697 201 9/14/2024 0.1.697 is deprecated.
0.1.691 326 9/13/2024 0.1.691 is deprecated.
0.1.686 171 9/13/2024 0.1.686 is deprecated.
0.1.672 390 9/12/2024 0.1.672 is deprecated.
0.1.667 207 9/11/2024 0.1.667 is deprecated.
0.1.664 142 9/11/2024 0.1.664 is deprecated.
0.1.653 260 9/11/2024 0.1.653 is deprecated.
0.1.639 330 9/10/2024 0.1.639 is deprecated.
0.1.634 178 9/10/2024 0.1.634 is deprecated.
0.1.623 310 9/7/2024 0.1.623 is deprecated.
0.1.600 575 9/6/2024 0.1.600 is deprecated.
0.1.582 337 9/5/2024 0.1.582 is deprecated.
0.1.578 135 9/5/2024 0.1.578 is deprecated.
0.1.575 125 9/4/2024 0.1.575 is deprecated.
0.1.518 363 9/2/2024 0.1.518 is deprecated.
0.1.512 1,139 8/30/2024 0.1.512 is deprecated.
0.1.508 131 8/29/2024 0.1.508 is deprecated.
0.1.506 202 8/28/2024 0.1.506 is deprecated.
0.1.505 145 8/28/2024 0.1.505 is deprecated.
0.1.504 132 8/28/2024 0.1.504 is deprecated.
0.1.503 176 8/27/2024 0.1.503 is deprecated.
0.1.502 136 8/27/2024 0.1.502 is deprecated.
0.1.497 131 8/27/2024 0.1.497 is deprecated.
0.1.495 131 8/27/2024 0.1.495 is deprecated.
0.1.486 138 8/9/2024 0.1.486 is deprecated.
0.1.481 288 8/8/2024 0.1.481 is deprecated.
0.1.479 142 8/8/2024 0.1.479 is deprecated.
0.1.474 137 8/7/2024 0.1.474 is deprecated.
0.1.471 169 8/7/2024 0.1.471 is deprecated.
0.1.470 114 8/7/2024 0.1.470 is deprecated.
0.1.467 132 8/7/2024 0.1.467 is deprecated.
0.1.455 122 7/31/2024 0.1.455 is deprecated.
0.1.454 98 7/30/2024 0.1.454 is deprecated.