Skip to content

Commit e5873ac

Browse files
committed
Use CallerArgumentExpression for TestDataRow by default.
1 parent f644ffa commit e5873ac

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

TUnit.Core/TestDataRow.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Runtime.CompilerServices;
2+
13
namespace TUnit.Core;
24

35
/// <summary>
@@ -20,7 +22,7 @@ internal interface ITestDataRow
2022
/// <typeparam name="T">The type of the test data.</typeparam>
2123
/// <param name="Data">The actual test data to be passed to the test method.</param>
2224
/// <param name="DisplayName">
23-
/// Optional custom display name for the test case.
25+
/// Optional custom display name for the test case. If not specified, the argument expression from <paramref name="Data"/> is used.
2426
/// Supports parameter substitution using $paramName or $arg1, $arg2, etc.
2527
/// </param>
2628
/// <param name="Skip">
@@ -33,15 +35,15 @@ internal interface ITestDataRow
3335
/// <code>
3436
/// public static IEnumerable&lt;TestDataRow&lt;(string Username, string Password)&gt;&gt; GetLoginData()
3537
/// {
36-
/// yield return new(("admin", "secret123"), DisplayName: "Admin login");
38+
/// yield return new(("admin", "secret123")); // DisplayName '("admin", "secret123")' is inferred
3739
/// yield return new(("guest", "guest"), DisplayName: "Guest login");
3840
/// yield return new(("", ""), DisplayName: "Empty credentials", Skip: "Not implemented yet");
3941
/// }
4042
/// </code>
4143
/// </example>
4244
public record TestDataRow<T>(
4345
T Data,
44-
string? DisplayName = null,
46+
[CallerArgumentExpression(nameof(Data))] string? DisplayName = null,
4547
string? Skip = null,
4648
string[]? Categories = null
4749
) : ITestDataRow

0 commit comments

Comments
 (0)