泛舟湖上清波郎朗
您可以使用此处提到的 ClassData来完成您创建了如下所示的某种 Generator 类,并将 ClassData 夹具与 Theory 结合使用。public class TestDataGenerator : IEnumerable<object[]>{ private readonly List<object[]> _data = new List<object[]> { new object[] {5, 1, 3, 9}, new object[] {7, 1, 5, 3} }; public IEnumerator<object[]> GetEnumerator() => _data.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();}public class ParameterizedTests{ public bool IsOddNumber(int number) { return number % 2 != 0; } [Theory] [ClassData(typeof(TestDataGenerator))] public void AllNumbers_AreOdd_WithClassData(int a, int b, int c, int d) { Assert.True(IsOddNumber(a)); Assert.True(IsOddNumber(b)); Assert.True(IsOddNumber(c)); Assert.True(IsOddNumber(d)); }}