Skip to content

Commit 3e153b6

Browse files
committed
fix: make MaxDurationMs a required constructor parameter in PerformanceBaselineAttribute
MaxDurationMs defaulted to 0 as an int property, causing every test to be flagged as exceeding the baseline when users wrote [PerformanceBaseline] without specifying MaxDurationMs. Make it a required constructor parameter so the compiler enforces a value at the call site.
1 parent 2063930 commit 3e153b6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

TUnit.Core/Attributes/TestMetadata/PerformanceBaselineAttribute.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace TUnit.Core;
2525
/// <example>
2626
/// <code>
2727
/// // Set a 500ms performance baseline
28-
/// [Test, PerformanceBaseline(MaxDurationMs = 500)]
28+
/// [Test, PerformanceBaseline(500)]
2929
/// public async Task FastOperation()
3030
/// {
3131
/// await DoWork(); // Warning if this takes longer than 500ms
@@ -35,17 +35,27 @@ namespace TUnit.Core;
3535
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
3636
public class PerformanceBaselineAttribute : TUnitAttribute, ITestEndEventReceiver
3737
{
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="PerformanceBaselineAttribute"/> class
40+
/// with the specified maximum duration.
41+
/// </summary>
42+
/// <param name="maxDurationMs">The maximum expected duration in milliseconds.</param>
43+
public PerformanceBaselineAttribute(int maxDurationMs)
44+
{
45+
MaxDurationMs = maxDurationMs;
46+
}
47+
3848
/// <summary>
3949
/// When set to <c>true</c>, performance baseline violations will cause the test to fail
4050
/// instead of emitting a warning. This is set by the engine when <c>--performance-baseline-fail</c> is specified.
4151
/// </summary>
4252
internal static bool FailOnViolation { get; set; }
4353

4454
/// <summary>
45-
/// Gets or sets the maximum expected duration in milliseconds.
55+
/// Gets the maximum expected duration in milliseconds.
4656
/// If the test exceeds this duration, a warning or failure is produced.
4757
/// </summary>
48-
public int MaxDurationMs { get; set; }
58+
public int MaxDurationMs { get; }
4959

5060
/// <inheritdoc />
5161
#if NET

0 commit comments

Comments
 (0)