【发布时间】:2016-11-13 06:06:19
【问题描述】:
我有一个测试方法如下:
[TestCase(new string[] { "1", "2", "5" }, Result = true)]
bool AllocateIDsTest1(IEnumerable<string> expected)
{
var target = ...
var actual = target.AllocateIDs(expected);
return actual.SequenceEqual(expected);
}
但是我得到一个编译器错误:
属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式。
可能编译器无法区分以下构造函数:
TestCase(params object[] args, Named Parameters);
和
TestCase(object ob1, Named Paramaters);
因为new string[] { "1", "2", "5" } 可以同时解析为params object[] 和object。
来自this post 我知道字符串数组应该可以作为编译常量传递。
如何向TestCase 提供字符串数组?
【问题讨论】:
标签: c# attributes nunit