我正在使用NUnit并尝试为以下方法实现测试:它应该接受两个整数并返回二维数组.所以,我测试的标题看起来像:
[TestCase(5, 1, new int[,]{{1}, {2}, {3}, {4}, {5}})]
public void MyTestMethod(int a, int b, int[][] r)
Run Code Online (Sandbox Code Playgroud)
在编译期间,我遇到以下错误:
错误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)
Run Code Online (Sandbox Code Playgroud)
但我仍有一个问题:只使用TestCase属性是否可以做到这一点?