【发布时间】:2012-03-03 21:33:11
【问题描述】:
我有以下测试:
[ExpectedException(typeof(ParametersParseException))]
[TestCase("param1")]
[TestCase("param1", "param2")]
[TestCase("param1", "param2", "param3", "optParam4", "optParam5", "some extra parameter")]
public void Parse_InvalidParametersNumber_ThrowsException(params string[] args)
{
new ParametersParser(args).Parse();
}
第一个 TestCase(显然)失败并出现以下错误:
System.ArgumentException : Object of type 'System.String'
cannot be converted to type 'System.String[]'.
我试图用这个替换 TestCase 定义:
[TestCase(new[] { param1 })]
但现在我得到以下编译错误:
错误 CS0182:属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式
我现在的解决方案是将“一个参数”的情况转移到不同的测试方法。
不过,有没有办法让这个测试以与其他测试相同的方式运行?
【问题讨论】:
标签: c# unit-testing nunit parameter-passing