Fuzzy 0.3.2

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

Build codecov Nuget

Fuzzy is a simple .NET API for fuzz testing, or more specifically, for generating fuzzy inputs in unit tests.

Why use fuzz testing? To prevent system under test from making incorrect assumptions about its inputs and make the unit tests more robust. Using Fuzzy for built-in and custom types in your unit tests also helps to make them smaller and cleaner.

install

Add the fuzzy package to your .NET project.

dotnet add package fuzzy

import

Import the Fuzzy namespace in your .NET source file.

using Fuzzy;

use

Create an IFuzz instance. Fuzzy is a fluent API starting with this interface.

IFuzz fuzzy = new RandomFuzz();

To get a fuzzy value of a type you need, look for an IFuzz extension method with the name of the type.

int foo = fuzzy.Int32();
double bar = fuzzy.Double();
string baz = fuzzy.String();
Uri qux = fuzzy.Uri();
TypeCode quux = fuzzy.Enum<TypeCode>();
TimeSpan quuz = fuzzy.TimeSpan();
DateTime corge = fuzzy.DateTime();

For supported types, you can also specify constraints, such as the minimum or the maximum value.

int foo = fuzzy.Int32().Minimum(41);
int bar = fuzzy.Int32().Maximum(42);
int baz = fuzzy.Int32().Between(41, 43);

Fuzzy can also create collections (Array or List) with fuzzy size and fuzzy elements.

int[] foo = fuzzy.Array(fuzzy.Int32);

If needed, you can constrain collection size

int[] foo = fuzzy.Array(fuzzy.Int32, Length.Between(41, 43));

and collection elements.

int[] foo = fuzzy.Array(() => Environment.TickCount);
int[] bar = fuzzy.Array(new[] { 41, 42, 43 });

With collections, you can also get a fuzzy element or a fuzzy index.

IEnumerable<string> elements = new[] { "foo", "bar", "baz" };
string element = fuzzy.Element(elements);
int index = fuzzy.Index(elements);

extend

Suppose you have the following type in your application.

class CustomType
{
    public int Foo;
    public string Bar;
}

If you create an extension method like this.

static class IFuzzExtensions
{
    public static CustomType CustomType(this IFuzz fuzzy) =>
        new CustomType {
            Foo = fuzzy.Int32(),
            Bar = fuzzy.String(),
        };
}

Then, you can create fuzzy values of this custom types, just like the of types already supported by Fuzzy.

CustomType value = fuzzy.CustomType();

And, if you need fuzzy values of one of the .NET framework types, consider contributing it to Fuzzy.

debug

Sometimes fuzzy test inputs can produce test results that are hard to understand or repeat. This is a sign that either your tests or your system aren't handling a particular input correctly. You will need to correct this by making your tests handle this input specifically and possibly adjust your system code. In the meantime, you can replace the RandomFuzz with the SequentialFuzz to make fuzzy values more predictable.

IFuzz fuzzy = new SequentialFuzz();
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.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Fuzzy:

Package Downloads
Chronology.Fuzzy

Fuzzy extensions for Chronology.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Fuzzy:

Repository Stars
microsoft/service-fabric-dotnet
Service Fabric .NET Libraries
Version Downloads Last Updated
0.3.2 0 6/14/2026
0.1.18 5,803 2/15/2021
0.1.17 740 11/16/2020
0.1.16 593 11/16/2020
0.1.12 629 11/7/2020
0.1.11 616 10/19/2020
0.1.9 657 10/19/2020
0.1.8 561 10/19/2020
0.1.6 595 10/18/2020
0.1.5 645 10/18/2020