c# - MSTest 命名参数数据行

标签 c# unit-testing mstest

可以使用 DataRow 属性(结合 DataTestMethod 属性)将数据传递给单元测试。但是,我想知道是否可以将数据传递给单元测试的命名参数。

例如,我现在必须做的:

[DataTestMethod]
[DataRow(1, null, 3)]
public void MyTest(int? first = null, int? second = null, int? third = null)
{
    // Test stuff...
}

然而,我希望能够:

[DataTestMethod]
[DataRow(first: 1, third: 3)]
public void MyTest(int? first = null, int? second = null, int? third = null)
{
    // Test stuff...
}

我知道这种语法不“可行”,它更像是传达我的问题的伪代码。

最佳答案

I want to know if it is possible to pass in data to named parameters of the unit test.

不,传递命名参数不是当前版本的 MSTest 中的可用功能。

关于c# - MSTest 命名参数数据行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49298668/

相关文章:

javascript - 如何在 React 和 Jest 中对 promise 拒绝进行单元测试

c# - 使用 Moq 验证采用委托(delegate)参数的基类中的方法调用

unit-testing - 使用 Shims 测试私有(private)方法

c# - KerberosRequestorSecurityToken 的 .Net 核心等效项是什么?

c# - EF 使用跳过并执行存储过程

c# - 是否可以创建 zedgraph 垂直标记?

c# - 如何在 Nest 中测试异常?

c# - 理解并创建 Python 协议(protocol)

c# - 只为单元测试添加代码不好吗?

c# - mstest异常处理方法