我正在使用 NUnit 并尝试为以下方法实现测试:它应该接受两个整数并返回二维数组。因此,我的测试标题如下所示:
[TestCase(5, 1, new int[,]{{1}, {2}, {3}, {4}, {5}})]
public void MyTestMethod(int a, int b, int[][] r)
在编译期间,我遇到以下错误:
错误 CS0182:属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式 (CS0182)
我知道可以使用TestCaseSource
引用对象数组来完成,例如以下问题的答案:
给出如下代码:
private object[][] combination_tests = new [] {
new object[] {5, 1, new [,]{{1}, {2}, {3}, {4}, {5}}},
};
[Test]
[TestCaseSource("combination_tests")]
public void MyTestMethod(int a, int b, int[,] r)
但我仍然有一个问题:是否可以只使用TestCase
属性来做到这一点?