【问题标题】:NUnit cannot recognise a TestCase when it contains an Nullable ArrayNUnit 在包含 Nullable 数组时无法识别 TestCase
【发布时间】:2014-12-01 08:55:36
【问题描述】:

我有这样的测试:

[Test]
[TestCase(new RequestStatus?[] {RequestStatus.Created, null, RequestStatus.Complete, null})]
public void MyClass_MyMethod( RequestStatus?[] testCaseRequest )
{
  ...
}

Nuint 无法将 Nullable Array 识别为 TestCase 参数。我得到了这个:

属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式

【问题讨论】:

标签: c# arrays nunit nullable testcase


【解决方案1】:

您可以使用params 作为方法参数:

[TestCase(RequestStatus.Created, null, RequestStatus.Complete, null)]
public void MyClass_MyMethod(params RequestStatus?[] requestStatus)
{
    // ...
}

【讨论】:

    猜你喜欢
    • 2013-07-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多