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
- Add Tests for TestCaseSource with IEnumerable Parameters Added tests to cover scenarios outlined in issue #1792 where an IEnumerable test case source paramter is applied to a single test parameter res... — committed to debugosaurus/nunit by debugosaurus 8 years ago
- Refactor TestCaseSourceAttribute Tests for Issue #1792 Refactored logic to determine TestCase parameters from TestCaseeSourceAttributes. Logic now should support transposing arrays (vertical) into me... — committed to debugosaurus/nunit by debugosaurus 8 years ago
- Refactor TestCaseSourceAttribute Tests for Issue #1792 Refactored logic to determine TestCase parameters from TestCaseeSourceAttributes. Logic now should support transposing arrays (vertical) into me... — committed to debugosaurus/nunit by debugosaurus 8 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
- *TestCaseSourceAttribute migrated to the new arguments aligning routine that adds support of params and optional arguments. Fixes #1792, Fixes #1883, See #2268, See #2104 — committed to StanEgo/nunit by StanEgo 7 years ago
@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!