我有方法:
public static int Add(List<int> numbers)
{
if (numbers == null || numbers.Count == 0)
return 0;
if (numbers.Count == 1)
return numbers[0];
throw new NotImplementedException();
}
这是我对它的测试,但它不喜欢new List<int> {1}
在 TestCase 中:
[TestCase(new List<int>{1}, 1)]
public void Add_WithOneNumber_ReturnsNumber(List<int> numbers)
{
var result = CalculatorLibrary.CalculatorFunctions.Add(numbers);
Assert.AreEqual(1, result);
}
它给了我错误:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
我是否必须这样做:
[Test]
public void Add_WithOneNumber_ReturnsNumber()
{
var result = CalculatorLibrary.CalculatorFunctions.Add(new List<int>{7});
Assert.AreEqual(7, result);
var result2 = CalculatorLibrary.CalculatorFunctions.Add(new List<int> {3});
Assert.AreEqual(4,result2);
}