使用 XUnit 将测试拆分为多个测试 - 避免循环

Splitting a test into multiple test with XUnit - Avoiding for loops

我看过很多讨论如何将数据集作为输入参数传递给 XUnit 测试的线程,但是要执行的示例总是只有非常有限的组合。
如果您要 运行 使用 N x M 组合进行测试怎么办?
一种简单的方法是编写一个测试,不接受输入参数,并简单地使用循环中的循环执行测试的所有组合。
然而,这种方法并不理想,因为它变得不可能(没有黑客)将失败的测试与通过的测试分开。要么全部通过,要么全部失败。

这里是我想避免并因此转换的使用循环的测试类型的一些草图:

[Fact]
public void NumberOfBytesPerBlockCannotExceedLimit()
{
    // Test setup
    ....

    // Repeat test for different number of bytes per word
    int[] bytesPerWordArray = new int[5] { 1, 3, 4, 6, 8, ... };
    foreach (int bytesPerWord in bytesPerWordArray)
    {
        // Repeat test N times, for different amount of reserved bytes
        int[] numReservedBytesArray= new int[5] { 1, 2, 3, 4, ... }; 
        foreach (int numReservedBytes in numReservedBytesArray)
        {
            // The actual test
            ...
        }
    }
}

现在,如何拆分此测试,而不必在内联或 IEnumerable/MemberData 中逐一键入每个 combination/vector?
理想情况下,bytesPerWordArray 和 numReservedBytesArray 都应该变成某种输入向量!?

这是一个如何使用 MemberData:

的例子
[Theory]
[MemberData(nameof(TestData))]
public void Test(int test1, int test2, int expected)
{
    var result = test1 + test2;
    Assert.Equal(expected, result);
}

public static IEnumerable<object[]> TestData()
{
    for (var i = 0; i < 5; i++)
    {
        for (var j = 0; j < 5; j++)
        {
            yield return new object[] { i, j, i + j };
        }
    }
}