【发布时间】:2012-05-21 14:22:42
【问题描述】:
我正在尝试使用 NUnit 并将字符串参数传递给 TestCase 属性,但我得到 “属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式” em>
这是一个简化的版本,但 MyStatic 是一个返回构建的 RegEx 字符串的调用,因此 MyStatic 中被调用的每个方法都附加到一个字符串构建器并隐式转换为字符串。
我想保留这种方法,因为如果我创建单独的单元测试,我将违反 DRY 原则。
[TestCase("","/123",MyStatic.DoThis().And().GetString("ABC"), "id","123")]
public void MyMehthod(string Root, string Path, string Route, string Param, string Expected)
{
var result = SetupRouteResponse(Root, Path, Route, "MatchIt");
Assert.AreEqual(Expected, (string)result.Context.Parameters[Param]);
}
【问题讨论】: