nunit: TestCaseSource: "Too many arguments provided" for IEnumerable<> parameter type

@debugosaurus commented on Wed Sep 14 2016

It appears that NUnit has started treating Array and Enumerable TestCaseSource parameters differently. I noticed this behaviour when upgrading from 3.0 to 3.4.1.0 (sorry that covers a lot of ground).

Say I declare some test data:

protected static IEnumerable<IEnumerable<string>> EnumerableOfStrings => new[] 
{ 
    new[] { "one", "two" }
};

The following test will pass:

[Test, TestCaseSource(nameof(EnumerableOfStrings))]
public void AcceptsArrayOfStrings(string[] array)
{
}

However this test will fail with the message “Too many arguments provided”:

[Test, TestCaseSource(nameof(EnumerableOfStrings))]
public void AcceptsEnumerableOfStrings(IEnumerable<string> enumerable)
{
}

It seems with the second test that NUnit is attempting to unbox the enumerable and pass each element as an argument rather than passing the enumerable as a single parameter.


@ChrisMaddock commented on Wed Sep 14 2016

I can reproduce this - agreed it seems to be a bug. (Great bug report, by the way! 👍)

I’ll also move this issue over to the NUnit framework repo - this ones just for doc issues. 😄

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@ChrisMaddock You’re right - this is not the situation I imagined. It could still be useful for whomever takes this one to explore the bounds of the problem by trying alternative formulations of the source.

Update: Ah… I see that’s you!