ZeroUnit 1.4.0

dotnet add package ZeroUnit --version 1.4.0
                    
NuGet\Install-Package ZeroUnit -Version 1.4.0
                    
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="ZeroUnit" Version="1.4.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroUnit" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroUnit">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroUnit --version 1.4.0
                    
#r "nuget: ZeroUnit, 1.4.0"
                    
#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.
#:package ZeroUnit@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroUnit&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroUnit&version=1.4.0
                    
Install as a Cake Tool

ZeroUnit

ZeroUnit is a zero-dependency unit-testing library for .NET. It generates a Program.cs that runs your tests. No Microsoft.NET.Test.Sdk or runtime dependencies needed.

Installing

Make the .csproj with your tests a console app and reference the ZeroUnit package:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="ZeroUnit"
    Version="1.4.0"
    ReferenceOutputAssembly="false"
    OutputItemType="Analyzer"
    ExcludeAssets="all" />
</ItemGroup>

Delete the class (usually named Program) with the Main method if it exists.

Writing tests

For ZeroUnit, a test is any method that:

  • is public and in a public class
  • has no parameters
  • has no return value (or returns a Task)
  • can be easily called (is either static or in a non-abstract class with a parameterless constructor)

A test passes if it does not throw any exceptions.

Use a parameterless constructor for setup and IDisposable.Dispose for teardown if needed.

Running tests

Run tests with dotnet run.

ZeroUnit generates a program that runs the tests in parallel. Non-static classes are instantiated for each test. Disposable classes are disposed.

Global setup and teardown

Add a Program class like this:

partial class Program
{
    static async Task<int> Main()
    {
        // global setup
        var failedTestCount = await RunTestsAsync();
        // global teardown
        return failedTestCount;
    }

    // ZeroUnit will implement this
    private static partial Task<int> RunTestsAsync();
}
There are no supported framework assets in this 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
1.4.0 215 6/8/2024
1.3.0 297 12/24/2023
1.2.0 263 12/23/2023
1.1.0 333 4/29/2023
1.0.1 313 4/20/2023