TUnit.Assertions.Analyzers 0.1.394-alpha01

Prefix Reserved
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.
dotnet add package TUnit.Assertions.Analyzers --version 0.1.394-alpha01                
NuGet\Install-Package TUnit.Assertions.Analyzers -Version 0.1.394-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.394-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.394-alpha01                
#r "nuget: TUnit.Assertions.Analyzers, 0.1.394-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.394-alpha01&prerelease

// Install TUnit.Assertions.Analyzers as a Cake Tool
#tool nuget:?package=TUnit.Assertions.Analyzers&version=0.1.394-alpha01&prerelease                

TUnit

T(est)Unit!

Documentation

See here: https://thomhurst.github.io/TUnit/

Features

  • Source generated tests
  • Full async support
  • Parallel by default, with mechanisms to switch it off for certain tests
  • Test ordering (if running not in parallel)
  • Tests can depend on other tests to form chains
  • Easy to read assertions
  • Injectable test data functionality
  • Hooks before and after: Assembly, Class, Test
  • Designed to avoid common pitfalls such as leaky test states
  • Ability to view metadata and results (if in a cleanup method) for a test from a TestContext object

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);
    }

or with more complex test orchestration needs

    [BeforeAllTestsInClass]
    public static async Task ClearDatabase() { ... }

    [AfterAllTestsInClass]
    public static async Task AssertDatabaseIsAsExpected() { ... }

    [BeforeEachTest]
    public async Task CreatePlaywrightBrowser() { ... }

    [AfterEachTest]
    public async Task DisposePlaywrightBrowser() { ... }

    [Retry(3)]
    [Test, DisplayName("Register an account")]
    [EnumerableMethodData(nameof(GetAuthDetails))]
    public async Task Register(string username, string password) { ... }

    [DataSourceDrivenTest, DependsOn(nameof(Register))]
    [EnumerableMethodData(nameof(GetAuthDetails))]
    public async Task Login(string username, string password) { ... }

    [DataSourceDrivenTest, DependsOn(nameof(Login))]
    [EnumerableMethodData(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)]
    [DataDrivenTest]
    [Arguments(1)]
    [Arguments(2)]
    [Arguments(3)]
    public async Task GoToPage(int page) { ... }

    [Category("Cookies")]
    [Test, Skip("Not yet built!")]
    public async Task CheckCookies() { ... }

    [Test, Explicit]
    [Property("Some Key", "Some Value")]
    public async Task Ping() { ... }

    public static IEnumerable<(string Username, string Password)> GetAuthDetails()
    {
        yield return ("user1", "password1");
        yield return ("user2", "password2");
        yield return ("user3", "password3");
    }

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

A .NET Testing Framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.442 295 7/13/2024
0.1.441 72 7/13/2024
0.1.440 75 7/13/2024
0.1.439 78 7/13/2024
0.1.438 116 7/12/2024
0.1.434 68 7/12/2024
0.1.433 67 7/12/2024
0.1.430 103 7/11/2024
0.1.428 78 7/10/2024
0.1.424 62 7/9/2024
0.1.423-alpha01 58 7/9/2024
0.1.422-alpha01 58 7/7/2024
0.1.420-alpha01 59 7/7/2024
0.1.419-alpha01 57 7/7/2024
0.1.418-alpha01 59 7/7/2024
0.1.417-alpha01 50 7/7/2024
0.1.416-alpha01 59 7/7/2024
0.1.413-alpha01 55 7/7/2024
0.1.412-alpha01 61 7/7/2024
0.1.411-alpha01 63 7/6/2024
0.1.410-alpha01 64 7/6/2024
0.1.409-alpha01 62 7/5/2024
0.1.407-alpha01 61 7/5/2024
0.1.406-alpha01 67 7/5/2024
0.1.405-alpha01 62 7/5/2024
0.1.404-alpha01 58 7/5/2024
0.1.403-alpha01 54 7/5/2024
0.1.402-alpha01 55 7/5/2024
0.1.401-alpha01 138 7/5/2024
0.1.398-alpha01 55 7/5/2024
0.1.397-alpha01 68 7/4/2024
0.1.395-alpha01 68 7/2/2024
0.1.394-alpha01 62 7/1/2024
0.1.392-alpha01 55 6/30/2024
0.1.391-alpha01 55 6/30/2024
0.1.390-alpha01 53 6/30/2024
0.1.389-alpha01 55 6/30/2024
0.1.386-alpha01 58 6/30/2024
0.1.385-alpha01 50 6/30/2024
0.1.384-alpha01 53 6/30/2024
0.1.383-alpha01 54 6/30/2024
0.1.382-alpha01 68 6/28/2024
0.1.381-alpha01 63 6/26/2024
0.1.380-alpha01 56 6/26/2024
0.1.379-alpha01 173 6/26/2024
0.1.378-alpha01 57 6/26/2024
0.1.377-alpha01 61 6/26/2024
0.1.376-alpha01 60 6/26/2024
0.1.375-alpha01 61 6/25/2024
0.1.374-alpha01 63 6/25/2024
0.1.373-alpha01 64 6/24/2024
0.1.372-alpha01 61 6/24/2024
0.1.371-alpha01 54 6/23/2024
0.1.370-alpha01 64 6/21/2024
0.1.369-alpha01 60 6/21/2024
0.1.368-alpha01 59 6/21/2024
0.1.367-alpha01 69 6/21/2024
0.1.366-alpha01 60 6/21/2024
0.1.365-alpha01 70 6/20/2024
0.1.364-alpha01 66 6/19/2024
0.1.363-alpha01 67 6/19/2024
0.1.362-alpha01 65 6/18/2024
0.1.361-alpha01 64 6/18/2024
0.1.360-alpha01 66 6/18/2024
0.1.359-alpha01 59 6/17/2024
0.1.358-alpha01 56 6/17/2024
0.1.357-alpha01 69 6/16/2024
0.1.356-alpha01 64 6/16/2024
0.1.355-alpha01 60 6/16/2024
0.1.354-alpha01 61 6/16/2024
0.1.353-alpha01 68 6/16/2024
0.1.352-alpha01 68 6/16/2024
0.1.351-alpha01 71 6/14/2024
0.1.350-alpha01 165 6/14/2024
0.1.349-alpha01 68 6/13/2024
0.1.347-alpha01 61 6/12/2024
0.1.346-alpha01 66 6/12/2024
0.1.343-alpha01 64 6/12/2024
0.1.342-alpha01 57 6/12/2024
0.1.341-alpha01 60 6/11/2024
0.1.340-alpha01 58 6/11/2024
0.1.338-alpha01 58 6/11/2024
0.1.336-alpha01 60 6/11/2024
0.1.335-alpha01 57 6/11/2024
0.1.334-alpha01 62 6/11/2024
0.1.333-alpha01 67 6/11/2024
0.1.332-alpha01 64 6/11/2024
0.1.331-alpha01 66 6/11/2024
0.1.330-alpha01 54 6/11/2024
0.1.329-alpha01 62 6/11/2024
0.1.328-alpha01 58 6/11/2024
0.1.327-alpha01 65 6/10/2024
0.1.326-alpha01 62 6/7/2024
0.1.325-alpha01 63 6/7/2024
0.1.324-alpha01 70 6/6/2024
0.1.323-alpha01 74 6/6/2024
0.1.322-alpha01 64 6/3/2024
0.1.321-alpha01 55 6/3/2024
0.1.320-alpha01 65 6/2/2024
0.1.319-alpha01 70 6/2/2024
0.1.318-alpha01 63 6/2/2024
0.1.317-alpha01 63 6/2/2024
0.1.316-alpha01 72 6/2/2024
0.1.315-alpha01 69 5/31/2024
0.1.314-alpha01 69 5/30/2024
0.1.313-alpha01 60 5/30/2024
0.1.312-alpha01 74 5/29/2024
0.1.311-alpha01 68 5/29/2024
0.1.310-alpha01 62 5/29/2024
0.1.309-alpha01 62 5/29/2024
0.1.308-alpha01 64 5/29/2024
0.1.307-alpha01 60 5/29/2024
0.1.306-alpha01 67 5/29/2024
0.1.305-alpha01 65 5/29/2024
0.1.303-alpha01 65 5/29/2024
0.1.302-alpha01 62 5/29/2024
0.1.301-alpha01 65 5/29/2024
0.1.300-alpha01 67 5/28/2024
0.1.299-alpha01 63 5/28/2024
0.1.298-alpha01 77 5/24/2024
0.1.297-alpha01 72 5/24/2024
0.1.296-alpha01 74 5/23/2024
0.1.295-alpha01 69 5/23/2024
0.1.294-alpha01 75 5/23/2024
0.1.293-alpha01 70 5/21/2024
0.1.292-alpha01 76 5/17/2024
0.1.291-alpha01 75 5/17/2024
0.1.290-alpha01 78 5/16/2024
0.1.289-alpha01 79 5/16/2024
0.1.288-alpha01 433 5/16/2024
0.1.287-alpha01 92 5/15/2024
0.1.286-alpha01 75 5/15/2024
0.1.285-alpha01 64 5/15/2024
0.1.284-alpha01 74 5/15/2024
0.1.283-alpha01 66 5/15/2024
0.1.282-alpha01 99 5/15/2024
0.1.281-alpha01 66 5/15/2024
0.1.280-alpha01 71 5/15/2024
0.1.279-alpha01 70 5/15/2024
0.1.278-alpha01 64 5/15/2024
0.1.277-alpha01 72 5/15/2024
0.1.276-alpha01 61 5/15/2024
0.1.275-alpha01 62 5/15/2024
0.1.274-alpha01 56 5/15/2024
0.1.273-alpha01 59 5/15/2024
0.1.272-alpha01 51 5/15/2024
0.1.271-alpha01 76 5/14/2024
0.1.270-alpha01 68 5/14/2024
0.1.269-alpha01 68 5/14/2024
0.1.267-alpha01 67 5/14/2024
0.1.266-alpha01 60 5/14/2024
0.1.265-alpha01 65 5/14/2024
0.1.264-alpha01 67 5/14/2024
0.1.263-alpha01 73 5/14/2024
0.1.262-alpha01 74 5/14/2024
0.1.261-alpha01 66 5/14/2024
0.1.260-alpha01 69 5/14/2024
0.1.259-alpha01 75 5/14/2024
0.1.258-alpha01 91 5/14/2024
0.1.257-alpha01 76 5/14/2024
0.1.256-alpha01 65 5/14/2024
0.1.255-alpha01 69 5/14/2024
0.1.253-pullrequest0116-0276 68 5/14/2024
0.1.253-pullrequest0116-0274 59 5/14/2024
0.1.253-pullrequest0116-0273 61 5/14/2024
0.1.253-alpha01 65 5/14/2024
0.1.252-alpha01 77 5/13/2024
0.1.251-alpha01 67 5/13/2024
0.1.250-alpha01 66 5/13/2024
0.1.249-alpha01 40 5/3/2024
0.1.248-alpha01 101 4/24/2024
0.1.247-alpha01 76 4/16/2024
0.1.246-alpha01 75 4/16/2024
0.1.245-alpha01 64 4/16/2024
0.1.244-alpha01 63 4/16/2024
0.1.243-alpha01 62 4/16/2024
0.1.242-alpha01 62 4/16/2024
0.1.241-alpha01 72 4/16/2024
0.1.240-alpha01 70 4/16/2024
0.1.239-alpha01 74 4/16/2024
0.1.238-alpha01 72 4/16/2024
0.1.237-alpha01 66 4/16/2024
0.1.236-alpha01 69 4/16/2024
0.1.235-alpha01 72 4/16/2024
0.1.234-alpha01 72 4/16/2024
0.1.233-alpha01 75 4/16/2024
0.1.232-pullrequest0073-0043 106 3/25/2024
0.1.232-alpha01 376 3/26/2024
0.1.231-pullrequest0073-0042 79 2/27/2024
0.1.231-pullrequest0073-0041 95 2/27/2024
0.1.231-pullrequest0073-0040 72 2/27/2024
0.1.231-pullrequest0073-0039 73 2/27/2024
0.1.231-pullrequest0073-0038 69 2/27/2024
0.1.231-pullrequest0073-0037 75 2/27/2024
0.1.231-PullRequest0073.3333 66 2/27/2024
0.1.231-alpha01 80 3/8/2024
0.1.230-alpha01 336 2/25/2024
0.1.229-alpha01 91 2/25/2024
0.1.228-alpha01 72 2/25/2024
0.1.227-alpha01 83 2/25/2024
0.1.225-alpha01 68 2/24/2024
0.1.224-alpha01 103 2/24/2024
0.1.223-alpha01 62 2/24/2024
0.1.222-alpha01 83 2/24/2024
0.1.221-alpha01 73 2/24/2024
0.1.219-alpha01 66 2/24/2024
0.1.218-alpha01 65 2/24/2024
0.1.217-alpha01 73 2/24/2024
0.1.216-alpha01 67 2/24/2024
0.1.215-alpha01 70 2/24/2024
0.1.214-alpha01 94 2/24/2024
0.1.213-alpha01 72 2/24/2024
0.1.212-alpha01 71 2/23/2024
0.1.211-alpha01 76 2/22/2024
0.1.210-alpha01 73 2/22/2024
0.1.209-alpha01 65 2/22/2024
0.1.208-alpha01 75 2/21/2024
0.1.207-alpha01 70 2/21/2024
0.1.206-alpha01 73 2/21/2024
0.1.205-alpha01 75 2/21/2024
0.1.204-alpha01 71 2/19/2024
0.1.203-alpha01 69 2/19/2024
0.1.202-alpha01 71 2/19/2024
0.1.201-alpha01 76 2/19/2024
0.1.200-alpha01 67 2/19/2024
0.1.199-alpha01 69 2/19/2024
0.1.198-alpha01 71 2/19/2024
0.1.197-alpha01 68 2/18/2024
0.1.196-alpha01 66 2/18/2024
0.1.194-alpha01 72 2/18/2024
0.1.193-alpha01 70 2/18/2024
0.1.191-alpha01 67 2/18/2024
0.1.190-alpha01 68 2/18/2024
0.1.189-alpha01 76 2/18/2024
0.1.188-alpha01 68 2/18/2024
0.1.187-alpha01 69 2/18/2024
0.1.186-alpha01 67 2/18/2024
0.1.185-alpha01 68 2/18/2024
0.1.184-alpha01 70 2/18/2024
0.1.183-alpha01 68 2/18/2024
0.1.182-alpha01 71 2/18/2024
0.1.181-alpha01 68 2/18/2024
0.1.180-alpha01 69 2/18/2024
0.1.179-alpha01 66 2/18/2024
0.1.178-alpha01 69 2/18/2024
0.1.177-alpha01 73 2/16/2024
0.1.176-alpha01 74 2/16/2024
0.1.175-alpha01 69 2/16/2024
0.1.174-alpha01 68 2/16/2024
0.1.173-alpha01 70 2/16/2024
0.1.172-alpha01 70 2/16/2024
0.1.171-alpha01 67 2/16/2024
0.1.170-alpha01 72 2/16/2024
0.1.169-alpha01 90 2/16/2024
0.1.168-alpha01 72 2/16/2024
0.1.167-alpha01 71 2/16/2024
0.1.166-alpha01 69 2/16/2024
0.1.164-alpha01 68 2/16/2024
0.1.163-alpha01 76 2/16/2024
0.1.162-alpha01 70 2/16/2024
0.1.158-alpha01 72 2/15/2024
0.1.157-alpha01 68 2/15/2024
0.1.155-alpha01 91 2/15/2024
0.1.154-alpha01 75 2/15/2024
0.1.153-alpha01 74 2/15/2024
0.1.152-alpha01 78 2/15/2024
0.1.151-alpha01 68 2/15/2024
0.1.150-alpha01 70 2/15/2024
0.1.149-alpha01 80 2/15/2024
0.1.148-alpha01 78 2/15/2024
0.1.147-alpha01 77 2/15/2024
0.1.146-alpha01 73 2/15/2024
0.1.145-alpha01 78 2/15/2024
0.1.144-alpha01 74 2/15/2024
0.1.143-alpha01 76 2/14/2024
0.1.142-alpha01 73 2/14/2024
0.1.141-alpha01 72 2/14/2024
0.1.140-alpha01 69 2/14/2024
0.1.139-alpha01 65 2/14/2024
0.1.138-alpha01 70 2/14/2024
0.1.137-alpha01 80 2/13/2024
0.1.136-alpha01 82 2/13/2024
0.1.135-alpha01 74 2/13/2024