对于像 2 或 4 这样的每个期望返回值,我想将此值作为单元测试方法的参数传递。但我得到一个例外,即参数不正确。当我删除 countExpected 参数时,单元测试运行良好,我无法断言 countExpected ...
NUnit 完全可以实现这种情况吗?
[Test, TestCaseSource("VisibleWeekDays")]
public void Test(DayOfWeek[] visibleWeekDaysSetup, int countExpected)
{
// ARRANGE
// ACT
// ASSERT
Assert.That(periods.Count(),Is.EqualTo(countExpected));
}
private static IEnumerable<TestCaseData> VisibleWeekDays
{
get
{
yield return new TestCaseData(new DayOfWeek[] {DayOfWeek.Sunday}).Returns(2);
yield return new TestCaseData(new DayOfWeek[] {DayOfWeek.Sunday, DayOfWeek.Monday}).Returns(4);
// more days...
}
}