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.
Can you tell me?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With