Skip to content

Commit a78374e

Browse files
thomhurstclaude
andauthored
fix: pass empty array to params parameter when [Arguments] has no values (#4572)
When [Arguments] is used with no arguments and the test method has a params parameter, the parameter now correctly receives an empty array instead of null. This matches standard C# behavior where calling a method with params and no arguments passes an empty array. Fixes #4561 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 34a94d2 commit a78374e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ public sealed class ArgumentsAttribute : Attribute, IDataSourceAttribute, ITestR
6262

6363
public ArgumentsAttribute(params object?[]? values)
6464
{
65-
if (values == null || values.Length == 0)
65+
if (values == null)
6666
{
6767
Values = [null];
6868
}
69+
else if (values.Length == 0)
70+
{
71+
Values = [];
72+
}
6973
else
7074
{
7175
Values = values;

TUnit.TestProject/ParamsArgumentsTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public async Task EmptyParamsArray(string name, params Type[] types)
4444
await Assert.That(types.Length).IsEqualTo(0);
4545
}
4646

47+
[Test]
48+
[Arguments]
49+
[Arguments("a")]
50+
[Arguments("a", "b")]
51+
[Arguments("a", "b", "c")]
52+
public async Task ParamsOnlyWithEmptyArguments(params string[] args)
53+
{
54+
// When [Arguments] has no values, params should be an empty array, not null
55+
await Assert.That(args).IsNotNull();
56+
}
57+
4758
[Test]
4859
[Arguments(1, "single")]
4960
public async Task SingleStringInParamsArray(int id, params string[] values)

0 commit comments

Comments
 (0)