Compze.xUnitMatrix 0.11.0-beta

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

Compze.xUnitMatrix

Run every test against every combination of your pluggable components. Automatically.

Define your component dimensions as enums. Create an attribute. Every test runs once per combination — no loops, no parameterized boilerplate, no copy-paste.

The problem

You have pluggable components — persistence layers, DI containers, serializers, transports. You need every test to pass with every supported combination. Without framework support, you end up with one of:

  • Copy-paste test classes per combination — unmaintainable
  • Parameterized tests with manual wiring — verbose and fragile
  • "We only test SQLite in CI" — then production breaks on PostgreSQL

How it works

1. Define your dimensions as enums

public enum PersistenceLayer { Sqlite, SqliteMemory, MicrosoftSql, PostgreSql, MySql }
public enum DIContainer { Microsoft, SimpleInjector, Autofac }

2. Create your attribute

public class MyMatrixAttribute(
   [CallerFilePath] string? sourceFilePath = null,
   [CallerLineNumber] int sourceLineNumber = -1)
   : MatrixTheoryAttribute<PersistenceLayer, DIContainer>(
      configurationFileName: null,
      sourceFilePath: sourceFilePath,
      sourceLineNumber: sourceLineNumber)
{
   public static PersistenceLayer PersistenceLayer => CurrentDimensionValue1;
   public static DIContainer DIContainer => CurrentDimensionValue2;
}

The generic type parameters define the matrix dimensions. With configurationFileName: null, every combination of every enum value runs automatically — the full Cartesian product.

CurrentDimensionValue1, CurrentDimensionValue2, etc. give type-safe access to the current combination's value for each dimension. Expose them as named properties for readability.

3. Use it

public class When_saving_data
{
   readonly IDatabase _db;

   public When_saving_data()
   {
      var persistence = MyMatrixAttribute.PersistenceLayer;
      var container = MyMatrixAttribute.DIContainer;
      _db = CreateDatabase(persistence, container);
      _db.Save(new Widget { Id = 1, Name = "sprocket" });
   }

   [MyMatrix] public void Saved_widget_can_be_loaded() =>
      _db.Load<Widget>(1).Name.Must().Be("sprocket");

   [MyMatrix] public void Loading_nonexistent_widget_throws() =>
      Invoking(() => _db.Load<Widget>(999)).Must().Throw<NotFoundException>();
}

Note: The assertions above use our Compze.Must fluent assertion library. You may want to check it out.

The constructor does setup using the current combination. Each test method is just an assertion. No parameters on the test methods — the combination flows via the attribute's static properties. In Test Explorer, each test appears once per combination with the combination shown in the test name.

Skipping specific combinations

Some combinations may not be supported. Skip them with [Skip<T>]:

[MyMatrix]
[Skip<PersistenceLayer>(PersistenceLayer.SqliteMemory, "Sqlite doesn't support this feature")]
public void Uses_advanced_sql_feature() { }

Multiple values from the same dimension can be skipped with one attribute:

[MyMatrix]
[Skip<PersistenceLayer>([PersistenceLayer.Sqlite, PersistenceLayer.SqliteMemory], "SQLite deadlocks under parallel writes")]
public void Multithreaded_test() { }

The generic type parameter ensures the enum type is preserved through IL metadata encoding, and the compiler prevents passing a value from the wrong enum type.

Any number of dimensions

Generic convenience base classes MatrixTheoryAttribute<T1> through MatrixTheoryAttribute<T1, T2, T3, T4, T5> cover the common cases — each exposes CurrentDimensionValue1 through CurrentDimensionValueN for type-safe access.

For more than 5 dimensions, inherit directly from the non-generic MatrixTheoryAttribute and pass the component enum types manually.

Configuration files

Sometimes you don't want to run every combination. A configuration file lets you list exactly which combinations to run — one per line, or with * as an auto-expanding wildcard:

# Only run these specific combinations
SqliteMemory:Autofac
SqliteMemory:SimpleInjector
*:Microsoft

The * on the third line expands to every PersistenceLayer value paired with Microsoft — Sqlite:Microsoft, SqliteMemory:Microsoft, MicrosoftSql:Microsoft, PostgreSql:Microsoft, MySql:Microsoft — for seven combinations total from three lines. Lines starting with # are comments.

Each line gives exactly one value, or *, for each dimension, in the order the attribute declares the dimensions, and each value is the exact name of one of its dimension's values. A file the matrix cannot use fails the test, with a message naming the problem: a file that doesn't exist or lists no combinations, or a line with a value too many or too few, or with a name that isn't a value of its dimension. So when you add a dimension, every configuration file that lists combinations for that matrix needs a value for it on each line.

Pass the file name as configurationFileName in your attribute constructor instead of null. The file is located relative to the test assembly's output directory, so configure your test project to copy it there:

<None Update="MyCombinations">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Installation

dotnet add package Compze.xUnitMatrix

Requires xUnit.net v3 4.0 or later. On xUnit.net v3 3.x, use version 0.9.1-beta.

Package Description
Compze.Must Fluent assertions (Must().Be(), Must().Throw<>(), etc.)
Compze.xUnitBDD BDD-style specification testing

License

Apache-2.0

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

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
0.12.1-beta 0 11/25/2026
0.12.0-beta 75 11/14/2026
0.11.0-beta 72 11/14/2026
0.10.0-beta 102 11/9/2026
0.9.1-beta 100 7/24/2026
0.9.0-beta 93 6/11/2026
0.5.0-beta 83 6/4/2026

### Changed
- A matrix test whose configuration cannot be used now fails, with a message saying what is wrong. It used to be skipped,
 which a passing test run hides. That covers a configuration file that does not exist or lists no combinations, a line in
 it that is not a combination of the matrix's dimension values, a dimension type that is not an enum, and a `Skip<T>` for a
 type that is not one of the dimensions or with no reason. A configuration that was broken before now fails the test run.
- Each line of a configuration file must give exactly one value, or `*`, for each dimension, and each value must be the
 exact name of one of its dimension's values. The failure names the file, the line and what is wrong with it.
- **Requires newer minor versions of other Compze packages:** Compze.Internals.SystemCE 0.7.0-internal (was 0.4.1-internal). Upgrading to this version upgrades each package listed here too, so their changelogs apply to this upgrade as well.

### Fixed
- A line with a value too many no longer runs as if the extra value were not there, and a line with a value too few no
 longer runs combinations short of a value. Both now fail the test. A line with a value too many and a `*` used to be
 skipped, with the message of an index out of range.
- A number in place of a value's name, such as `7`, no longer gives a value the enum does not define, and a
 comma-separated list of names, such as `MsSql,Postgre`, no longer gives their values combined, which could be another
 of the enum's values. Both now fail the test.
- Two matrices with different dimensions that name the same configuration file now each get the combinations of their own
 dimensions. The second one used to get the combinations read for the first.
- `*` for two dimensions of the same enum type now expands both. It used to be skipped, with the message "Sequence contains
 more than one matching element".