将字符串数组传递给 xunit 测试方法 [英] Pass array of string to xunit test method
本文介绍了将字符串数组传递给 xunit 测试方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将一个字符串数组传递给我的一个 XUnit 测试方法,但是当我执行以下操作时它不起作用(数组 + 参数机制)
I want to pass an array of string to one of my XUnit test method, but when I just do the following it doesn't work (array + params mechanism)
[Theory]
[InlineData(new object[] { "2000-01-02", "2000-02-01" })]
public void TestSynchronizeMissionStaffing_PeriodNoMatch(string[] dateStrings)
我可以像这样解决这个问题:
I can work around the issue like this:
[Theory]
[InlineData(0, new object[] { "2000-01-02", "2000-02-01" })]
public void TestSynchronizeMissionStaffing_PeriodNoMatch(int dummy, string[] dateStrings)
但我希望有更好的方法来解决这个问题.
But I'm hoping there something better to resolve the issue.
你能告诉我吗?
推荐答案
使用 params
在方法的 string[]
参数之前,然后你就不需要初始化 string[]
在 InlineData
属性中,而您可以使用可变数量的 string
文字,编译器不会为此抱怨一点:
Use params
before the method's string[]
argument, and then you won't need to initialize a string[]
in InlineData
attribute, rather you could use a variable number of string
literals, for which the compiler doesn't complain one bit:
[Theory]
[InlineData("2000-01-02", "2000-02-01")]
public void TestSynchronizeMissionStaffing_PeriodNoMatch(params string[] dateStrings)
这篇关于将字符串数组传递给 xunit 测试方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文