XUnit3Helper 0.0.5-alpha

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

XUnit3Helper

en ru

A utility library for convenient work with xUnit v3. Designed to speed up writing parameterized tests and to simplify preparing mocks in DI containers.

Key features

  • Attribute JsonFileDataAttribute — load data for Theory from a JSON file (multiple formats, sections).
  • Attribute CustomAutoDataAttribute — ready-made configuration for AutoFixture + AutoMoq (including ConfigureMembers and recursion behavior).
  • Extension MockExtension.AddMocks — bulk registration of Moq mocks into IServiceCollection.
  • Helper generator GenerateTestDataExtension and model TestData — support for deserializing JSON into parameter sets up to 15 arguments.
  • Supported targets: net8.0, net9.0, net10.0.

Usage

  1. JsonFileDataAttribute
  • Constructor: JsonFileDataAttribute(string filePath, bool simpleTypeJson = false, string? sectionKey = null)
  • Behavior:
    • Checks that the file exists.
    • If sectionKey is specified, extracts the corresponding JSON section (top-level key).
    • Supports two JSON formats:
      • "Complex" — an array of objects with fields P1, P2, ... (matches the TestData models).
      • "Simple" (simpleTypeJson = true) — an array of arrays or an array of strings/numbers, where each element of an inner array corresponds to a test parameter.
    • Limitation: up to 15 parameters (the test-case generation logic is implemented for 1..15 parameters).
  • Examples: Complex data format (recommended):
[
    {
        "P1": 1,
        "P2": "a",
        "P3": true
    },
    {
        "P1": 2,
        "P2": "b",
        "P3": false
    }
]

Simple types format (simpleTypeJson = true):

[
    [1, "a", true],
    [2, "b", false]
]

Usage in tests:

    [Theory, JsonFileData("testdata.json")]
    public void MyTest(int a, string b, bool flag)
    {
        // ...
    }
    [Theory, JsonFileData("simple.json", simpleTypeJson: true)]
    public void SimpleTest(int a, string b)
    {
        // ...
    }
    [Theory, JsonFileData("config.json", sectionKey: "cases")]
    public void SectionedTest(int x, int y)
    {
        // ...
    }
  1. CustomAutoDataAttribute
  • A simplified attribute for use with AutoFixture + AutoMoq.
  • Configuration:
    • Adds AutoMoqCustomization with ConfigureMembers = true.
    • Removes ThrowingRecursionBehavior and adds OmitOnRecursionBehavior to safely generate object graphs.
  • Example:
    [Theory, CustomAutoData]
    public void AutoFixtureTest(MyService sut, int n)
    {
        Assert.NotNull(sut);
    }
  1. MockExtension.AddMocks
  • An extension for IServiceCollection: for each provided Type it registers:
    • Mock<T> as scoped,
    • T (mock.Object) as scoped.
  • Removes existing registrations for the type before adding the mock.
  • Example:
    var services = new ServiceCollection();
    services.AddMocks(typeof(IMyService), typeof(IOtherService));

or with generics (implemented via reflection for each type in the code).

License

  • MIT
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 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 XUnit3Helper:

Package Downloads
XUnit3Helper.Integration

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.5-alpha 269 11/13/2025
0.0.4-alpha 100 11/8/2025
0.0.3-alpha 141 10/30/2025