NUnitAssertGen 1.0.0

dotnet add package NUnitAssertGen --version 1.0.0
                    
NuGet\Install-Package NUnitAssertGen -Version 1.0.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="NUnitAssertGen" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NUnitAssertGen" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NUnitAssertGen" />
                    
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 NUnitAssertGen --version 1.0.0
                    
#r "nuget: NUnitAssertGen, 1.0.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 NUnitAssertGen@1.0.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=NUnitAssertGen&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NUnitAssertGen&version=1.0.0
                    
Install as a Cake Tool

NUnitAssertGen

Generates NUnit Assert.That statement strings from live object instances using reflection. Paste the output directly into your test methods — no more hand-writing assertions for complex objects.

Installation

dotnet add package NUnitAssertGen

Quick start

using NUnitAssertGen;

var result = myService.GetPerson(42);
Console.WriteLine(AssertGenerator.Generate(result, "result"));

Example output:

Assert.That(result.Name, Is.EqualTo("Alice"));
Assert.That(result.Age, Is.EqualTo(30));
Assert.That(result.Tags, Is.EquivalentTo(new HashSet<string> { "admin", "user" }));
Assert.That(result.Scores, Has.Count.EqualTo(2));
Assert.That(result.Scores.ContainsKey("math"), Is.True);
Assert.That(result.Scores["math"], Is.EquivalentTo(new HashSet<int> { 95, 87 }));
Assert.That(result.Address.Street, Is.EqualTo("123 Main St"));
Assert.That(result.Address.ZipCode, Is.EqualTo(90210));

API

// Default options
string code = AssertGenerator.Generate(instance, "result");

// Quick depth override
string code = AssertGenerator.Generate(instance, "result", maxDepth: 3);

// Full control
string code = AssertGenerator.Generate(instance, "result", new GeneratorOptions { ... });

GeneratorOptions

Property Type Default Description
MaxDepth int 5 Maximum recursion depth into nested objects. A comment is emitted when the limit is hit.
IncludePrivateProperties bool false Also reflect non-public instance properties.
IncludeFields bool false Include public instance fields alongside properties.
PropertyFilter Func<PropertyInfo, bool>? null Predicate to exclude properties by name, type, or attribute.
FieldFilter Func<FieldInfo, bool>? null Predicate to exclude fields. Only applies when IncludeFields is true.
EmitCountAssertions bool true Emit Has.Count.EqualTo(n) before per-element assertions on non-empty collections.
MaxCollectionItems int int.MaxValue Cap on inline collection items; excess items produce a truncation comment.
SortDictionaryKeys bool false Emit dictionary entries in ascending key order for deterministic output.
NullHandling NullHandling AssertIsNull AssertIsNull, AssertNotNull, or Skip.
UnreadablePropertyBehavior UnreadablePropertyBehavior Comment Comment, Skip, or Throw when a property getter throws.
FloatTolerance double? null Emit .Within(tolerance) on float/double assertions instead of exact equality.
DateTimeFormat DateTimeFormat Parse Parse (DateTime.Parse("…")), Ticks (new DateTime(ticks, kind)), or Constructor (new DateTime(y,m,d,…)).
EnumFormat EnumFormat FullyQualifiedName FullyQualifiedName, ShortName, or NumericCast.
FallbackFormatter Func<object, string?>? null Custom formatter for types the generator does not recognise. Return null to fall back to ToString().
GroupPropertiesByObject bool false Insert a blank line between assertion groups for each nested object.

Supported types

Type Generated assertion
Primitives (int, string, bool, Guid, DateTime, decimal, …) Is.EqualTo(…)
HashSet<T> / ISet<T> Is.EquivalentTo(new HashSet<T> { … })
Dictionary<K, V> Has.Count + ContainsKey + value per entry
Dictionary<K, HashSet<V>> Above, with nested Is.EquivalentTo(…)
List<T> / T[] (primitive element) Is.EquivalentTo(new[] { … })
List<T> / T[] (complex element) Has.Count + per-index recursion
Nested objects Recurses into public readable properties
null Controlled by NullHandling option
DateOnly / TimeOnly new DateOnly(…) / new TimeOnly(…) (.NET 6+)
Enums Controlled by EnumFormat option

License

MIT © ameritusweb

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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.

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.0.0 38 3/19/2026