diff --git a/docs/articles/nunit/writing-tests/attributes/maxtime.md b/docs/articles/nunit/writing-tests/attributes/maxtime.md index 706dd355b..2544f275e 100644 --- a/docs/articles/nunit/writing-tests/attributes/maxtime.md +++ b/docs/articles/nunit/writing-tests/attributes/maxtime.md @@ -18,6 +18,12 @@ MaxTimeAttribute(int milliseconds) |-----------|------|-------------| | `milliseconds` | `int` | The maximum elapsed time in milliseconds. If the test exceeds this time, it fails. | +## Named Parameters + +| Parameter | Type | Description | +|-----------|------|-------------| +| `WarningTime` | `int` | An optional warning threshold in milliseconds. If the test takes longer than this time but less than the maximum time, the test result is set to `Warning`. A value of `0` (the default) disables the warning threshold. (**NUnit 5+**) | + ## Applies To | Test Methods | Test Fixtures (Classes) | Assembly | @@ -34,6 +40,10 @@ MaxTimeAttribute(int milliseconds) [!code-csharp[MaxTimeVsAssertions](~/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs#MaxTimeVsAssertions)] +### Warning Threshold + +[!code-csharp[MaxTimeWarningThreshold](~/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs#MaxTimeWarningThreshold)] + ## Notes 1. Any assertion failures take precedence over the elapsed time check. If a test both fails an assertion and exceeds the time limit, the assertion failure is reported. @@ -41,6 +51,7 @@ MaxTimeAttribute(int milliseconds) 3. For tests that need to be cancelled when they exceed a time limit, use [CancelAfter Attribute](xref:attribute-cancelafter) instead. 4. The timing includes the test method execution only, not `SetUp` or `TearDown` methods. 5. The [Timeout Attribute](xref:attribute-timeout) uses `Thread.Abort` and only works on .NET Framework. +6. The optional `WarningTime` named parameter (added in **NUnit 5+**) sets a soft threshold: if the test exceeds it but still passes within the maximum time, the result is `Warning` rather than `Failure`. ## See Also diff --git a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs index 35b94111c..5b7211eb9 100644 --- a/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs +++ b/docs/snippets/Snippets.NUnit/Attributes/MaxTimeAttributeExamples.cs @@ -50,5 +50,20 @@ public void AssertionFailuresTakePrecedence() } } #endregion + + #region MaxTimeWarningThreshold + [TestFixture] + public class MaxTimeWarningThresholdTests + { + [Test] + [MaxTime(1000, WarningTime = 200)] + public void OperationWithWarningThreshold() + { + // Test passes if it completes within 1000ms. + // If it takes more than 200ms but less than 1000ms, the result is Warning. + Thread.Sleep(201); + } + } + #endregion } } diff --git a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj index e51bb029b..dddd7796f 100644 --- a/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj +++ b/docs/snippets/Snippets.NUnit/Snippets.NUnit.csproj @@ -10,7 +10,7 @@ - + all