我有以下试验:传递单个值PARAMS参数在NUnit的测试用例
[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();
}
第一测试用例(显然)失败,错误如下:
System.ArgumentException : Object of type 'System.String'
cannot be converted to type 'System.String[]'.
我试图更换测试用例与这一个定义:
[TestCase(new[] { param1 })]
但现在我收到以下编译错误:
error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
我现在的解决方案是将'单参数'情况移到不同的测试方法。
还有,有没有办法让这个测试和其他测试一样?
您链接到ReSharper的问题,而问题似乎是在nunit ......在任何情况下,似乎resharper解决了这个问题 – Noctis 2014-10-03 05:35:02
这样做与'new [] {...}'数组是字符串给出错误CS0182引用上面的OP。整数类型似乎正常工作。 – Brandon 2015-02-23 18:21:19