Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass array of string to xunit test method

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?

like image 321
Serge Intern Avatar asked Apr 05 '16 07:04

Serge Intern


1 Answers

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) 
like image 101
yair Avatar answered Sep 22 '22 02:09

yair