From 96542c655e621bca281024a16f0c193181ed1c63 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 27 Jan 2026 00:59:24 +0000 Subject: [PATCH] fix: pass empty array to params parameter when [Arguments] has no values 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 --- TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs | 6 +++++- TUnit.TestProject/ParamsArgumentsTests.cs | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs b/TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs index 974ebd8232..8ad3d88d69 100644 --- a/TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs +++ b/TUnit.Core/Attributes/TestData/ArgumentsAttribute.cs @@ -62,10 +62,14 @@ public sealed class ArgumentsAttribute : Attribute, IDataSourceAttribute, ITestR public ArgumentsAttribute(params object?[]? values) { - if (values == null || values.Length == 0) + if (values == null) { Values = [null]; } + else if (values.Length == 0) + { + Values = []; + } else { Values = values; diff --git a/TUnit.TestProject/ParamsArgumentsTests.cs b/TUnit.TestProject/ParamsArgumentsTests.cs index 78ad3eb7fe..d13feaf495 100644 --- a/TUnit.TestProject/ParamsArgumentsTests.cs +++ b/TUnit.TestProject/ParamsArgumentsTests.cs @@ -44,6 +44,17 @@ public async Task EmptyParamsArray(string name, params Type[] types) await Assert.That(types.Length).IsEqualTo(0); } + [Test] + [Arguments] + [Arguments("a")] + [Arguments("a", "b")] + [Arguments("a", "b", "c")] + public async Task ParamsOnlyWithEmptyArguments(params string[] args) + { + // When [Arguments] has no values, params should be an empty array, not null + await Assert.That(args).IsNotNull(); + } + [Test] [Arguments(1, "single")] public async Task SingleStringInParamsArray(int id, params string[] values)