DnDGen.Stress 5.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package DnDGen.Stress --version 5.0.2
                    
NuGet\Install-Package DnDGen.Stress -Version 5.0.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="DnDGen.Stress" Version="5.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DnDGen.Stress" Version="5.0.2" />
                    
Directory.Packages.props
<PackageReference Include="DnDGen.Stress" />
                    
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 DnDGen.Stress --version 5.0.2
                    
#r "nuget: DnDGen.Stress, 5.0.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 DnDGen.Stress@5.0.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=DnDGen.Stress&version=5.0.2
                    
Install as a Cake Addin
#tool nuget:?package=DnDGen.Stress&version=5.0.2
                    
Install as a Cake Tool

DnDGen.Stress

A framework for running stress tests against random generators

Build Status

Random generators are hard to test: a bug might only show up once in a few thousand runs. Stressor runs a test over and over, until either a time limit expires or enough iterations have completed to be confident in the result. Any failure on any iteration fails the test, with the original stack trace preserved.

It is built for NUnit and is used by the other DnDGen generator libraries.

Installing

dotnet add package DnDGen.Stress

Version 5 requires .NET 10 and NUnit 5. Use version 4.x if you are still on .NET 8 or NUnit 4.

Usage

Create a Stressor once per test fixture, then call it from your tests.

using DnDGen.Stress;
using NUnit.Framework;

[TestFixture]
public class MyGeneratorStressTests
{
    private Stressor stressor;
    private MyGenerator generator;

    [OneTimeSetUp]
    public void StressSetup()
    {
        var options = new StressorOptions();
        options.RunningAssembly = typeof(MyGeneratorStressTests).Assembly;

#if STRESS
        options.IsFullStress = true;
#else
        options.IsFullStress = false;
#endif

        stressor = new Stressor(options);
    }

    [SetUp]
    public void Setup()
    {
        generator = new MyGenerator();
    }

    [Test]
    public void StressGenerate()
    {
        stressor.Stress(() =>
        {
            var thing = generator.Generate();
            Assert.That(thing.Name, Is.Not.Empty);
        });
    }
}

Methods

Method What it does
Stress(test) Runs test repeatedly until the time limit or the confidence iterations are reached.
Stress(setup, test, teardown) Same as above, but runs setup before and teardown after every iteration. teardown runs even if test throws.
StressAsync(test) Async version of Stress. Runs MaxAsyncBatch tests concurrently per batch.
StressAsync(setup, test, teardown) Async version with per-iteration setup and teardown.
Generate(generate, isValid) Calls generate until isValid returns true, then returns the result. It has no time limit of its own, so use it inside Stress or GenerateOrFail.
GenerateOrFail(generate, isValid) Calls generate until isValid returns true, and fails the test if the time limit is reached first. Useful for verifying that a rare result can be generated.

After each run, Stressor logs a summary (duration, iterations, iterations per second, and likely status) through ILogger. By default it logs to the console; pass your own ILogger to the Stressor(options, logger) constructor to change that.

Options

Option Default Description
IsFullStress false When false, every stress test runs for 1 second. When true, the time limits below apply.
RunningAssembly null The test assembly. Used to count the active (non-ignored) [Test] and [TestCase] methods in it.
TestCount 0 The number of stress tests, if you would rather set it directly. Set exactly one of RunningAssembly or TestCount.
BuildTimeLimitInSeconds 3600 (1 hour) The total time budget for all stress tests, divided evenly among them.
OutputTimeLimitInSeconds 600 (10 minutes) The maximum time a single stress test may run. Useful for build systems that fail a step with no output for too long.
TimeLimitPercentage 1 Scales both time limits, to leave headroom for setup and non-stress tests. Must be greater than 0 and at most 1.
ConfidenceIterations 1,000,000 A stress test stops early once it completes this many iterations.
MaxAsyncBatch Environment.ProcessorCount How many async tests run concurrently per batch.

In full stress mode, each test's time limit is:

min(BuildTimeLimitInSeconds * TimeLimitPercentage / testCount, OutputTimeLimitInSeconds * TimeLimitPercentage)

Running a full stress build

The usage example above switches on full stress with a STRESS compilation symbol. The .NET SDK defines a symbol from the build configuration name, so building with a configuration named Stress is enough:

dotnet test -c Stress

This repository's own build pipeline does exactly that.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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 DnDGen.Stress:

Package Downloads
DnDGen.Stress.Events

A framework for running stress tests against random generators, including assertions of event spacing

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.7 125 11/13/2026
5.0.6 104 11/9/2026
5.0.5 107 11/7/2026
5.0.4 155 10/28/2026
5.0.3 111 10/27/2026
5.0.2 114 10/22/2026
5.0.1 118 10/22/2026
5.0.0 152 10/20/2026
4.1.5 338 5/8/2026
4.1.4 385 2/25/2026
4.1.3 333 2/17/2026
4.1.2 217 1/21/2026
4.1.1 473 8/12/2025
4.1.0 525 1/2/2025
4.0.1 451 11/20/2024
4.0.0 380 7/12/2024
3.5.1 549 1/11/2024
3.5.0 497 12/11/2023
3.4.0 934 1/11/2023
3.3.0 774 3/28/2022
Loading failed

No changes to the package since 5.0.1. If you are upgrading across several versions, see each version's changes at https://github.com/DnDGen/DnDGen.Stress/releases