I'm new to unit testing and nUnit in general and I'm not sure what I'm trying to do is possible or if I'm using the right syntax (in C#).
I want to pass for a test a collection of IEnumerable using the TestCaseSource
attribute and to compare it a collection of results but in a way that the X argument from the first collection would be tested against the X argument from the second with the Sequential
attribute.
Something like this:
[Test]
[TestCaseSource("ListCases"), Sequential]
public void FormatListTest( [Values()] IEnumerable ListCases,
[Values("0,2,3", "1,thanks,<3", "0", "")] string listResult)
{
string result = FormatUtils.FormatList(ListCases);
Assert.AreEqual(listResult, result);
}
static object[] ListCases =
{
new object[] {0,2,3},
new object[] {"1","thanks","<3"},
new object[] {0},
new object[] {},
};
Obviously, it doesn't work. While writing this question I figured out that what I need to do is:
[Test]
[Sequential]
public void FormatListTest( [Values(new object[] { 0, 2, 3 },
new object[] { "1", "thanks", "<3" },
new object[] {0},
new object[] {})] IEnumerable ListCases, [Values("0,2,3", "1,thanks,<3", "0", "")] string listResult)
{
string result = FormatUtils.FormatList(ListCases);
Assert.AreEqual(listResult, result);
}
But I'm still curious for future use if I can "route" different sources for several inputs (inputs and expected results that is) to assert one against its expected result is some fashion using TestCaseSource and Sequential at the same time.
For all intents and purposes, I'm using it for a Unity game but all the code above have nothing to do with Unity directly (besides running it) or with MonoBehaviour.