I want to test a method with List<List<string>> as parameter. I am using xunit as testing framework.
Here is what I tried.
public static IEnumerable<IEnumerable<string>> CombinationData
{
get
{
return new List<List<string>>
{
new List<string>{ "a", "b", "c" },
new List<string>{ "x", "y", "z" }
};
}
}
[Theory]
[MemberData(nameof(CombinationData))]
public void CombinationDataTest(List<List<string>> dataStrings)
{
...
}
I get the following exception when the run the test.
System.ArgumentException :
Property CombinationData on CodeUnitTests.MainCodeTests yielded an item that is not an object[]
Stack Trace: at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
How do I make it work ? Is it the right approach ?
Error message is pretty clear. Function provided for
MemberDatashould returnIEnumerable<object[]>, whereIEnumerableis collection of parameters for one test caseobjectinobject[]is parameter expected by test methodYour test method expect
List<List<string>>as parameter so you should return instance ofList<List<string>>as first item ofobject[]